Hey, btw, you don't need a blank-identifier there, simply type:

package main

func main() {
println("Hello world")
for range [3]int{} {
println("Yay")
}
}

On Monday, December 19, 2011 at 1:18:33 AM UTC+3, Christoffer Hallas wrote:
>
> I have a hard time understand people who complain about this.
>
> How can it bother you, and turn you off, that you have to write 
> understandable and maintainable code?
>
> If you just want to print out "Yay!" three times, simply:
>
> package main
>
> func main() {
> println("Hello world")
> for _ = range [3]int{} {
> println("Yay")
> }
> }
>
> On a side note, I'd like to see an actual use for a program that does this.
>
> Newcomers to Go needs to see Go for what it is. For me it's a tool that 
> helps me with a lot of things, including becoming somewhat a better 
> programmer, at least it forces me to appreciate the pretty little details 
> that makes me proud of what I do, like a carpenter would appreciate a 
> beautifully crafted piece of wood.
>
> And I don't think you're an idiot. :)
>
> Best regards
>
> On Sat, Dec 17, 2011 at 12:19 AM, Brett <[email protected] <javascript:>> 
> wrote:
>
>> Hey all,
>>
>> I've been trying to learn and use Go more. I wanted to share with you the 
>> difficulty I found as a beginner with the specific error "declared and not 
>> used". I thought the best way to illustrate how this felt to me is by 
>> showing you a beginner's session from the Go playground.
>>
>>
>> Round 1: Run hello world
>>
>> package main
>> import "fmt"
>> func main() {
>>   fmt.Printf("Hello World\n")
>> }
>>
>>
>> > Hello World
>>
>>
>>
>> Round 2: Cool; now let me try a nice literal
>>
>> package main
>> import "fmt"
>> func main() {
>>   fmt.Printf("Hello World\n") 
>>
>>   foo := []int{1,2,3}
>>
>> }
>>
>>  
>>
>> prog.go:5: foo declared and not used
>>
>>
>> Round 3: Doh; well, at least it compiled otherwise; I'll just use it in a 
>> loop, that should fix it
>>
>> package main
>> import "fmt"
>> func main() {
>>   fmt.Printf("Hello World\n") 
>>
>>   foo := []int{1,2,3}
>>
>>   for i := range foo {
>>     fmt.Printf("Yay\n")
>>   }
>>
>> }
>>
>> prog.go:6: i declared and not used
>>
>>
>> Round 4: Doh again; searched around a bit and found mention of the blank 
>> identifier (http://golang.org/doc/effective_go.html#maps); I'll try that
>>
>> package main
>> import "fmt"
>> func main() {
>>   fmt.Printf("Hello World\n") 
>>
>>   foo := []int{1,2,3}
>>
>>   for _ := range foo {
>>     fmt.Printf("Yay\n")
>>   }
>>
>> }
>>
>> prog.go:6: no new variables on left side of :=
>>
>>
>> Round 5: Doh thricely; I guess I need the other kind of equals sign or 
>> something
>>
>> package main
>> import "fmt"
>> func main() {
>>   fmt.Printf("Hello World\n") 
>>
>>   foo := []int{1,2,3}
>>
>>   for _ = range foo {
>>     fmt.Printf("Yay\n")
>>   }
>>
>> }
>>
>> > Hello world
>>
>> Yay
>>
>> Yay
>>
>> Yay
>>
>>
>> At last!
>>
>>
>> My first impression was that I was getting a lot of errors for such 
>> simple beginner code. This turned me off a lot. As I have continued writing 
>> more complex programs, I still find myself grappling with "declared and not 
>> used" frequently. I'm not sure why this is the case; maybe I'm a 
>> breadth-first coder and build scaffolding too early?
>>
>> Either way, I'm concerned this kind of thing is hurting the adoption of 
>> Go. I expect people on this list to say "you're just an idiot". But 
>> seriously, I think this little thing may be important. So 
>> hypothetically, what minimal changes to Go (language, tools) could improve 
>> this experience for beginners?
>>
>> Thanks,
>>
>> -Brett
>>
>>
>> PS: If you agree with me but are embarrassed, feel free to reply 
>> privately and I'll keep your identity a secret!
>>
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to