Learning a new computer language can be fun! Stretching ourselves to think about problems in new ways..
Learning the language R was like that. It was exciting because it was different than anything else I’d used and you could do powerful things with very little code.
First Impressions
Trying to come up to speed on the go language feels very different; more like a challenge to figure out things that should be simple and are not, at least for me now.
Go has a very “C” like feel, but without some of the things I’m used to. Preprocessor macros, unions, bitfields, ternary operator and various shortcuts I’m used to using. Many of the idioms used with C are not available, such as using ints for boolean truth; (i.e. you must do an explicit compare with zero). Increment and decrement are statements and can’t be used in expressions.
The go language formatter is annoying as it likes to use tabs for indenting, while I’ve been using a few spaces for years (decades?).
I’ve only been using (learning) go for a few days, so doing even simple things was frustrating, hitting the reference docs for almost everything; but this is normal in learning a new language.
Having said that, I think it holds promise for doing co-routines (go routines) and programs that require performance not available with typical scripting languages. Slicing and dicing arrays is cool. Packages for handling unicode, data conversions, bit twiddling, big numbers, complex numbers, networking functions and having maps available are all cool too.
Therefore, I’ll be continuing the struggle (until it isn’t anymore).
First Program
IMO, the best way to come up the learning curve on a new language is to write something with it. You can read about how to swim, but you really need to jump in to really learn it.
The sudoku solver I wrote in awk and C (and described here) was my chosen challenge, so I could compare the code, do a little benchmarking and publish the results.
The most difficult sudoku problem that I’ve found requires over 3 million calls to search(), inuse() and about double that for the mark() function. It takes about 32s with awk on my macbook, which, for what it does isn’t bad.
For the compiled versions, I executed the binaries 100x to get a reading. The C version with no optimization was 25s, with optimization it was 9s. The go version was 11s; so, pretty darn fast and a few orders of magnitude faster than the original awk version.
Not much of a consideration these days, but I should also mention the size of the binaries produced. Both the C versions compiled to 9kb binaries, while the go version compiled to over 2mb; a few orders of magnitude larger. This is only a toy program however. The difference would be smaller in a non-trivial system and not as much of a concern these days anyway.
I’ve only been fiddling with go for a few days, so be kind! The repo is available here:
https://github.com/billduncan/solve-go
As a side note, the language has a bit of a “rust-like” feel as well..