Now, I may have shot myself in the foot ever-so-slightly on this one, as I actually think the C example is better looking. Regardless of looks; functionally, I prefer the Go example as it sets us up more readily for packaging up our software. I however, did not write these examples to say which is nicer. I wrote them to show how similar they are.
When I call Go "Shorthand C," it really makes sense when you look at writing more complex programs, dealing with large programs, and concurrency. There is a really
neat blog post here comparing C and Go, and detailing some of the finer things about the Go vs. C syntax.
Alright, now that we’ve gone over some of the basics, and seen the Go syntax vs. the C syntax, let’s get heavy. LOAD TESTING! It’s time to see if Go can really hold a candle to other languages, and if the claims of many developers are indeed true.
(Here’s a hint--they are.)
Now then, down to the interesting part--the nitty gritty, the part we’ve all been waiting for! How speedy is Go? From my experience having written both C and Go, I am already aware of Go’s speed relative to C. But let’s have a look at how Go stacks up next to Ruby running a variety of simple but repetitive programs.
YUP!! You read that right! As you can see from the stats above, Golang is incredibly more efficient than standard Ruby! In our first program, ‘fasta-redux’, the program took 110.37 seconds to execute and exit. That’s over a minute! Go, on the other hand, did it in an astonishing 1.79 seconds! Almost 100x times faster!
Despite what I may often say, it’s not
all about the speed. Go also handles concurrency in a much more favorable way than most languages. Go uses very lightweight threads called
Goroutines. These Goroutines can be spun up in their thousands and by using channels, they can concurrently pass messages around in your program.
So, we’ve got useful default packages, super fast speeds, an excellent syntax, awesome concurrency, and hundreds of great online resources to help you along your Go journey. So what’s missing?
Well, like anything, Go isn’t 100% perfect. In my opinion, some of the function outputs from the default packages aren’t as good as they could be, and the default testing suite leaves a lot to be desired. There are a few more things that niggle at me, but I’ll leave that to another blog post!
Going back to the good points of Go--it is now being widely adapted by startups and enterprise companies alike. Many Saas/Paas providers use Go in their projects, and
SendGrid is now adopting it. At SendGrid, we’re rewriting features of our core system in Go. This aims to make SendGrid more robust, faster, and even more reliable!
To wrap this up, if you’re looking for a concurrent, parallel, simple, sexy, and awesome programming language to learn, look no further! Go is definitely worth taking a look at!
I’ve listed some excellent online resources to start your journey below!
- @rbin