Disclaimer: I’ve been studying Go for two days. There are some neat things I learned about it, so I decided to document them, but if anything in this post is factually inaccurate, please let me know so I can correct it. Thanks!
For some examples: Go has a main method that works just like Java, and one variable initialization style,
x := 10, since there’s no explicit type declaration. Overall, in Go, you type way less characters than you do in any other language I’ve used before. Look at the idiomatic initialization above. Or look at how you get a character from an array:
arr, unlike Java,
Now for the weird stuff that’s not like any other language I know – though it might be like some other language.
Go only has one loop, which happens to use the
for keyword. Using different syntax patterns, it can operate like a for loop, a for-each loop, and a while loop, just to name a few. There’s also a range loop
for k := range arr, and if another language I know uses them it’s definitely esoteric.
Go also does a weird thing with arrays. There are three standard types of array-like things: arrays, slices, and maps. Arrays pretty much work like Java: they have a set type and size and can’t be expanded. To fix the “arrays can’t be expanded but I wannaaaaa” problem, instead of going the Java route and making an array-style expandable object type which everyone then uses instead of standard arrays (ArrayList), Go has “slices”. These are segments of arrays which can be expanded when new elements are appended, until the length of the slice exceeds the length of the array, at which point the contents of the array are copied to a new array which is big enough to hold the appended elements. …I think. Maps are, fortunately, simpler. They’re sets of key-value pairs, where the keys and values can be of any single type. So you can map strings to ints, ints to ints, strings to strings, etc.
There are two things about Go which I find neither good nor bad, just very interesting. The first thing is that, among the variously-sized numeric types, there exist numeric types for complex numbers. This sparked a sudden desire in my mind to do something involving quantum physics with Go, although I have absolutely no idea what about quantum physics I would want to write a computer program for. The second thing is that Go does a lot of stuff in the Terminal, which makes me wonder how one goes about writing desktop applications in the language. (According to this article, it’s difficult.) I’m not a huge fan of web development stuff in general, and it’d be kind of annoying to have to make all my advanced Go projects web-based.
Besides slices, nothing about Go seems too awful or counterintuitive, so I’m optimistic about my future studies. As soon as I’ve got something a bit more complicated than Hello World, I’ll post projects and write-ups here. Please look forward to it!