Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Actually, the following is valid syntax in Go 1.0 and later:

    var i = 0
The use of "var" without a type is a common idiom when binding global variables, such as:

    var ErrTooLarge = errors.New("bytes.Buffer: too large")
Oddly, the := shortcut is not legal in the global context. Also fun:

    var (
        i = 0
        j = 0
    )
So, going back to the original comment -- yes, Go has some odd little shortcuts and inconsistencies.


Why is := not valid in the global context? I have been bitten by this time and time again. Is there a reason for it? It makes no sense to me.


I believe the answer is related to the simplicity of the parser.


I see, thank you. Too bad this wart is exposed, though.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: