News for hackers. Stuff that matters.
Re:5 Weeks of Go by exim on Wednesday May 23, 2012 @01:42PM (#4014244)
Could someone point out, what is the reasoning of putting types after variable names? i.e. why not `int i` instead of `var i int` ?
Re:5 Weeks of Go by qznc on Wednesday May 23, 2012 @02:16PM (#4014463)
It is more readable, if have multiple declarations, since the names are aligned instead of the types.

  var x int
  var foo map[string]int
  var dummy []int
compared to

  var int x
  var map[string] int foo
  var []int dummy
Re:5 Weeks of Go by iand on Wednesday May 23, 2012 @01:54PM (#4014324)
Re:5 Weeks of Go by ori_b on Wednesday May 23, 2012 @03:45PM (#4014940)
It's easier to parse. You don't have to do the lexer hack (http://en.wikipedia.org/wiki/The_lexer_hack), for example.
Re:5 Weeks of Go by drivebyacct2 on Wednesday May 23, 2012 @01:47PM (#4014279)
This is mentioned somewhere but it removes the ambiguity and bugs that can be introduced by pointer types.

Consider: int* i, j (or rather int *i, j)

Re:5 Weeks of Go by to3m on Wednesday May 23, 2012 @02:34PM (#4014572)
Well, there's no ambiguity in this case, because "int" is a keyword, known to the compiler, and will always be interpreted as a type. But if you had something like "x*y,z", then the meaning of this would depend on whether x is a type or not.
Re:5 Weeks of Go by singular on Wednesday May 23, 2012 @03:31PM (#4014869)
I think this is more in reference to the common C error of:-

    int* x, y;
when you meant to declare both x and y as int pointers, here only x will be a pointer and y will be a straight int.

Obviously the go designers could have chosen to simply make this mean that both x and y are pointers, however this would be somewhat confusing for those familiar with C.

As iand says, there is a rather good article on this which goes into a lot more detail - http://golang.org/doc/articles/gos_declaration_syntax.html