Anyway, since my last post I’ve moved my family from Northern Virginia to the Florida coast to take a new job (I’ve discovered that the DC area does not agree with me), so I’ve been a bit distracted. However, now that I’m (mostly) settled in and not constantly unpacking, setting up house, fixing things, etc., I have some time to pursue my side projects again. I had been working on a training tracker tool in Scala, but decided to mothball that one for the time being, as interest from potential customers just wasn’t there.
For now, I’ve decided to explore a few new technologies. I’ve always wanted to learn about NoSQL databases, but I just never had a product idea that seemed to call for a non-relational database solution. So, I’ve been messing around with CouchDB… and while I’m just messing around, I decided to play with this new Go programming language I’ve been hearing so much about lately.
First Impressions
I remember hearing about Go several years ago when it was first introduced. At the time I was spending my spare time playing around with Ruby on Rails, and at first blush Go looked very, very similar to C:
package main import "fmt" func main() { fmt.Println("Hello, 世界") }
I mean, static typing?! Web development was going to be moving to dynamic languages like Ruby and Python anyway, why waste my time with this thing?
Second, er, impressions
Fast forward a couple of years. My day job involves writing web services and applications mostly in Java (sometimes Scala and Javascript). While Scala is a fine language, and I used it as the primary language on my last side project, you will never catch me coding in Java during my free time. Writing Java is tedious, frustrating, and always feels like work. But it pays the mortgage, it does.
Since I was having trouble generating ideas for a new project, I decided to spend some time learning a new language. Go was/is gaining in popularity (and version 1.3 of the language was released just a few months ago), so I decided to give it a second look. I figured devoting a few weeks to Go wouldn’t kill me (probably). I stepped through the excellent Tour of Go and decided my initial opinion of Go was misplaced. Here was a delightfully small, concise language with actually decent concurrency support (It’s no Akka, but goroutines and channels took me minutes to grasp as opposed to days/weeks with Akka).
Here’s an excerpt from the concurrency section on Tour of Go:
package main import "fmt" func sum(a []int, c chan int) { sum := 0 for _, v := range a { sum += v } c
To briefly explain the fun bits involving concurrency, placing the keyword ‘go’ before a function call (as in go sum() ) fires off a goroutine, which is executed concurrently with the main thread of execution. Go hides the complexities of managing threads, pools, etc., from you in a way that just works.
Go also allows you to send data between goroutines using channels. The line:
c
writes the value of sum to channel c. You can see that the main function reads from that channel (actually, it reads from it twice) with the line:
x, y := <-c,
incidentally, this line of code blocks main() until two values from channel c are received, so you do have to be mindful of what you’re doing when using channels 🙂
If you’ve ever written concurrent code (or had to debug a multi-threaded application), this probably seems too easy. I’ll admit it’s not as powerful as Akka actors. Though – to explain Akka actors to somebody, its concomitant messaging scheme, dispatching, etc., I’d probably need several hours and a whiteboard (or a chalkboard, or a sidewalk).
This kind of simplicity and well thought out language design is why I think Go is going to become very popular in the near future. It really does strike me as C, modernized. Unlike Scala, Erlang, etc., here’s a language designed for modern network programming, with pretty darn good concurrency support, that isn’t a bear (or ocelot) to learn. The most common (admittedly legitimate) concern expressed to me by my bosses whenever I suggested using, say, Scala is the lack of readily available Scala devs out there: “If I need a new Java developer, I can find one pretty much on demand. Scala developers are hard to find, AND more expensive.” And even though a smart developer can learn Scala, it’s such an advanced (and feature-rich) language that it’s going to take a considerable amount of time before a new Scala dev can be productive (especially if said dev doesn’t have experience with functional programming). But with Go — you really ought to be able to pick it up in a few days. And it has the advantage of not being Java, which is a good thing, always.
Conclusion
I do believe I’ll stick with getting better at programming in Go for a little while and will probably make use of it whenever I can 🙂
Oh, and I figured a good project to learn more about Go and CouchDB would be… a Go driver for CouchDB 🙂 I know there are already several out there (some good, some … not), but I figured this would be a good vehicle for learning Go (and couch) and so far it has been — see my repo here.
The Gopher mascot and logo were designed by Renée French, who also designed Glenda, the Plan 9 bunny. The logo and mascot are covered by the Creative Commons Attribution 3.0 license.[1]; permission