Sunday, March 18, 2012

Experiences in Go-ing

I've been messing around with Go for quite some time now and I wanted to share my experiences.

When I first looked at Go, I put it aside as "just another language", and moved on with whatever I was doing.

I mean, there are languages popping up every day that are worth nothing whatsoever because the ideas they bring to the table are too few to take the risk of using a language that isn't popular (less documentation, less support, less everything).

That summer, I began writing some more low-level C/C++ code to implement a Bayesian classifier stock recommend-er thing. It was a complete disaster.

Just some basic string parsing was a nightmare; C gave no utilities whatsoever, and C++ was good, until I hit an error and it gave me a 20 line long error report, and, I had to use all kinds of specialized templates for the simplest of things!

And, the worst problem I faced was of sockets. Non-blocking, multi-plexed and cross-platform socket support with C is basically non-existent (unless I wanted to use libev or libevent, which has documentation scattered across the internet in small chunks). With C++, there are many choices, such as Boost.Asio (basically no documentation), ACE and ICE (this one I'm genuinely excited about, but, I hate their specialized object format crap I have to deal with).

And, of course, there's no language support for anything so if I ever wanted to distribute my code, the client would have to have the libraries.

I couldn't sacrifice performance (lots of number crunching was involved with costs tight), so, I couldn't pick Python.

Then, I came back to Go, and looked at it again from a different perspective, and hoped it would offer me something that could rid me of all of this.

I never did in fact write the Bayesian classifier thing (the idea wasn't much good anyway), but, the project introduced me to Go, which, I must say, is an amazing language.

The first thing I immediately noticed is that they got rid of the parentheses in "if" and "for" statements. Coming from Python, I really like this.

And, here's a language that's FINALLY SUPPORTING UNICODE FROM THE START!

Closures are supported and functions can be passed around like salt shakers, its wonderful!

All of the language seems well-thought out and cohesive; there aren't really any points that I felt like didn't match with the rest of system. Its very much like a suit without any stitch marks on it.

As for the standard library, its no short of awesome. It includes a lot of things that I've frequently wanted with C/C++ as part of the runtime, such as json, xml, http, a cryptography package, even websocket support built right in.

And, when they say it feels dynamic and interpreted, they actually mean it; the type system steps out your way for most of the time.

The only thing I find lacking is that there are no books on the language as of yet, but, I expect that will be remedied once the language is "marketed" a bit more (Google hasn't put a ton of weight on it ... yet).

It also has support for RPC which makes writing distributed computations really easy and quick.

Unless I have to write some really low-level code, I refrain from using C/C++ these days and instead reach for Go; about the same speed with half the development time.

I really encourage you to go check out Go, and just play around with it; you might start using it all the time.

18 comments:

  1. Try LoseThos http://www.losethos.com and maybe do a blog on it!

    ReplyDelete
  2. haskell is what go will be in 1000 years

    ReplyDelete
    Replies
    1. Theoretically pure doesn't always mean practical.

      Delete
    2. What does that even mean? Do you mean to imply that Haskell is less practical than Go? Because that's definitely not true...

      Haskell may have too many Ivory Tower Dwellers in the community, but it also has humans, and is much more mature/stable than Go (being more than a decade older).

      Not to say one shouldn't use Go :) Whatever does the job for you.

      Delete
    3. I think you misunderstood. He is saying Haskell is way ahead of Go. Hence the "Haskell is today what Go will be in a 1000 years".

      Delete
    4. They have very different design goals. There's no "ahead of" to speak of...

      Delete
  3. Replies
    1. Looks interesting, I will probably check it out and post a review here :)

      Delete
  4. Have you considered translating your (R)Python program with PyPy? I must say I have never faced any problems with C++ when it comes to what you say, but I may be wrong.

    ReplyDelete
    Replies
    1. I've used PyPy, and I must say its quite nice, but, there are some small issues with it that prevent me from using it from a large project (e.g. not all libraries work)

      You've seriously never thought that cross platform socket code in C++ really sucked? (except with Qt, that's a pretty big exception, but, that involves a "precompiler" that makes it kind of doesn't make it C++ anymore)

      Delete
  5. Easier than PyPy would be to just try using Cython and doing some basic type annotation in your Python code. You get a C module out that is going to be orders of magnitude faster than your pure python code.

    ReplyDelete
  6. "And, here's a language that's FINALLY SUPPORTING UNICODE FROM THE START!"

    I thought Java had Unicode in 1.0.

    Best
    Stephan
    http://codemonkeyism.com

    ReplyDelete
    Replies
    1. He is right though. C, C++ and Ruby, for instance, doesn't.

      Delete
    2. Java's Unicode was good when they launched, true, but now they (and C#, I'm told) only support the old two-byte, unfinished version of Unicode that's missing many characters.

      Delete
    3. Ruby (1.9) does support Unicode.

      Delete
    4. C/C++, Ruby 1.8.x , Python 2.x all have messed up Unicode.

      Delete
  7. Just curious, do you prefer Python to Go in general nowadays?

    ReplyDelete
    Replies
    1. Not in particular; depends on what I'm doing.

      A lot more jobs for Python, though.

      Delete