A Tour of Go
go-tour.appspot.com
go-tour.appspot.com
I've never written a Go program so I don't know if it comes up in practice, but it seems like this kind of variability makes it harder to learn and harder to read other people's code (who may not use the same constructs you use). Something I really appreciate about Python is that it's syntactically extremely simple and there are very few surprises.
Variables in Go can be a bit tricky, but it's really not too difficult. In functions, declaring a variable with "var" requires a type and optionally and initializer. The ":=" construct declares and initializes a new variable whose type is inferred to be that of the righthand expression. Again it's just a convenience so you can stop repeating yourself.
It's mostly a matter of style and verbosity, the only thing you have to care about is that you can't use the ":=" outside of functions. And as that will give you compilation errors, you'll notice quickly. No different behavior or runtime faults.
Three ways? I only count two, and the rule for what to use is very simple: any time the type can be inferred from the initial value, you use := (obviously you can't use := in other cases, so there isn't really any ambiguity).
It is quite different when compared to python, but it is probably better compared to C, C++ or even Java. C is nearly 40 years old, a lot of the decisions that were made in its creation look silly now (terminating strings with '\0'? yeah, great choice). From what I can see of Go, they try to address many of these aging conventions.
Why? What would have been better?
The only alternative I know about is saving the size of the string, but that comes with its own little set of problems.
Of course, something like C++ strings might need more processing to do basic things, but between the OS latency/overhead, I/O times and human perception, you wouldn't notice any difference at all.
import "fmt"
Why would anyone designing language in this decade would allow cryptic names like this in their "Hello World" code? Besides I still can't see single compelling reason to throw away all my tools and libraries in exchange of this thing. Do people create language just for the hack of it?
But I don't think Go qualifies as a sheer 'hack value' language. We're talking about something developed under the auspices of Google here. They're looking for a systems programming language, which really hasn't been the focus of recent years (compared to scripting or VM language implementations). The only real contender here are some functional languagues who've gotten fast enough and have some good compilers, but not everybody wants to go all the way in that direction. Considering that Google does a lot of Java, Python and C++, something more in that family seems wanted, and I think Go qualifies here.
Considering that this is the latest language in the C/Unix family and the pedigree of its designers and implementers (Rob Pike, Russ Cox, Ken Thompson(!)), some idiosyncrasies are too be expected. Unix has always been rather fond of abbreviations (`man creat`), and `fmt` doesn't seem any weirder than `stdio.h` – or `printf`.