5 ms·
Nothing in go is silly. There are multiple reasons why it's required. The answer usually given is faster compile times and the removal of semicolons from the
by amattn 15y ago
Nothing in go is silly. There are multiple reasons why it's required.
The answer usually given is faster compile times and the removal of semicolons from the language. I don't know the details, but someone new complains about it on the mailing list fairly frequently.
Also having a tool enforced brace style is just plain practical. Less silly arguments/bikeshedding.
I was also a brace on its own line kinda guy, but between javascript and go, I've gotten over it.
- mbreese 15y agoPerhaps this will be Go's version of Python's whitespace issue. People will balk at the seemingly arbitrary nature of the syntax and avoid trying the language. However, after time, the rest of the language's advantages will lead people to get over their syntax aversion and try the language. Then after 6 months they'll look back and wonder what the big fuss was before. Not that I have any experience with that...
- karterk 15y agoWhat about using two characters for assignment? a := 1 vs a = 1
- kinghajj 15y ago":=" is type-inferred variable declaration and assignment, while "=" is just assignment.
- alextgordon 15y agoIt is a bit annoying having to press 3 keys using two hands instead of just one. With '=' I can "hyperthread" my typing. While I'm finishing the LHS and pressing space I can move my right hand to press '=', while keeping my left hand thumb in place to press the space bar for the right side. With ':=' I have to stop everything to press shift with my left hand, then press ':', then release shift and press '='. It's very inefficient for something that happens often.
- drbawb 15y agoI've never really had a big issue with this. I have no issue keeping my thumb on the spacebar while holding left shift, and in addition I've grown to rather like the syntax. In the long run I'd say multiple assignment probably saves you more time writing declarations than an extra key-stroke would cost you.
- jff 15y agoJust think about how much more you'd have to type if you were programming C, and you'll be ok :) My main gripe with := vs = is that as I change my code, an existing := may suddenly become invalid, meaning I have to go back and change it when compilation fails, or vice versa.
- georgemcbay 15y agoYes, but thankfully compilation fails rather than succeed and then fail in some mysterious way at runtime. As someone who has been stuck writing JavaScript for Yahoo Widgets (Vizio Connected TV) over the past month, my appreciation for the compiler errors you get in static languages has grown tremendously. Previously I had taken them too much for granted.
- nfriedly 15y agoYou might appreciate jslint or closure-compiler - both have their quirks, but they can be tremendously helpful at finding certain errors.
- adgar 15y agoHaving both := and = goes back a long, long, long way. Go isn't even the 100th language to differentiate them.
- 4ad 15y ago:= and = don't do what you probably think they do, the meaning is not the same as in Pascal. If you need to compare two variables, you use == if a == b {} = is the usual assignment, := declares and initializes a variable inferring the type. var a int a = 42 vs. a := 42 That means you'll see explicit types in variable declarations rarely.
- JulianMorrison 15y ago"a := 1" means "var a int = 1" which is not the same as "a = 1"