Lately I have been looking for some solid alternatives to Ruby, and I must admit up-front – Rails spoiled me, badly.
I was hungry for some performance boosts, and let’s face it – dynamically typed languages can get you until some point.
I played with few popular modern languages (manually dealing with memory management? No thank you sir) and tried to hook them into Rails application.
So first, Crystal – it felt great (look at me, I’m writing compiled Ruby that is magnitude faster!), but the language itself is so immature at this point that basically each release breaks something (in a major way). There are some external libraries in active development, you can find some basic tools for postgres, redis, http lib etc. I really like shards – dependency manager, so you can plug in some goodies into your project – after all, it’s all about ecosystem of the language.
Overall I really like it, I hope the crystal team will manage to ship some stable version this year (the most recent news was kinda a turn off), but I would rather wait a little but more. So I ended my journey with Crystal pretty quick.
Started by Mozilla in around 2010. API at this point seems quite stable, and the language itself feels pretty great, mostly because zero-cost abstractions. I recommend this awesome full stack fest talk about writing Ruby extensions in Rust where Yehuda Katz goes into some details about language specifics. Rust have great official documentation, and pretty sweet dependency manager called cargo – something like Rubygems / npmjs, but for Rust.
I tried to write some more meaningful that Hello world web app in Rust, and at this point it felt a little bit awkward. I think mostly because tools are still in the works (check out are we web yet webpage). But the development activity in rust community is so active I wouldn’t be surprised that we will be web in next few months.
Accounted in 2009 by Google, pretty damn stable as major version is released like twice a year. Pretty awkward dependency management (you have to choose something from this list yourself), very verbose error checking might seem like a big turn-off at first, but after giving it some time I kinda liked it.
Starting from zero you can relatively quickly build some tiny app that spits out JSON that can be consumed by your Rails app. If you have to crunch and aggregate some bigger amounts of data in-memory even badly written go code should run much faster than your carefully profiled ruby code (well, GC is sooo costly in Ruby) – even considering network latency between two applications.
I took some extra time to do some proof of concept in Go and extracted part of the Rails logic into separate go lang app, then just hooked them two together via JSON, here are my thoughts:
building complex sql queries in Go – super awkward, there are some sql query builders, but I don’t think any of them can handle like complex nested joins with select right, I ended up gluing query inside custom struct with a help of sqlx. There are so ORMs out there I didn’t tried as I didn’t really needed one.
gotta love gofmt, same goes for go compiler that does a lot of code validation for you (where in ruby you would have to write tests in go it just doesn’t compile in the first place) – if you’re using sublimetext it has quite neat package for go
concurrency in go is quite cheap – you will be amazed how easy you can speed things up even further
Next step: some sane production deployment pipeline (docker maybe?) and real-world benchmarks.