Crystalling with the Ruby programming language

Skrevet 5. May, 2017 i Programming Languages, Software Development, af Thomas Peter Berntsen

I must confess that I’m a bit of a Rubyist at heart. Not that I am religious about my choice of programming language - I’m a polyglot and like and write my code in a number of different programming languages - but I just really like the Ruby syntax. At a very personal level I think it’s very clean and beautiful, and it resonates very well with my aesthetic preferences.

The Ruby community is excellent, helpful and has produced some wonderful works, like the ever popular Ruby on Rails web framework, and the wonderfully whimsical why’s Poignant Guide to Ruby. The Ruby community has also, in a lot of ways, been thought leading in ways of agile software development, software testing, continuous delivery, and DevOps for more than a decade.

That performance thing

However, even Rubyists joke about the performance of Ruby, and although the performance is not the primary source of the greatly exaggerated decline of Ruby (which is still way up there on the TIOBE index), it is a topic that needs to be dealt with when working with high-performance applications such as websites and SaaS with a high volume of requests and a large number of users.

That microservice thing

Lately, the so-called microservice architecture has won acclaim as a reasonable method of designing more complex systemes out of a landscape of smaller and interdependent services, and shortly after the Go programming language was created, it found itself as being one of the preferred languages to implement such microservices with.

Now, Go has a lot of good merits when it comes to its design, architecture, and commercial backers, and with its mature web frameworks it has supported wildly performant web applications that pull the socks off of Rails performance-wise. And it being able to package itself into a single executable (with runtime environment and all) makes it ideal for implementing microservices.

But it just so happens that there are other newer kids on the block that have some of the same characteristics: being fast, some with static type checking, producing single binaries suitable for microservices, and with great communities.

Rust comes to mind, as does Nim. Swift (also a wonderfuld language) is itself rapidly evolving becoming a general purpose programming language suitable for server-side programming.

And then there is Elixir, which doesn’t produce that coveted single binary, but which is elegant (do I need to mention that it’s Ruby-inspired), very mature (thanks, Erlang), and performant like 20 cups of coffee in the morning brewed on Red Bull.

Crystal

And finally there is Crystal. Oh, you beautiful Ruby’esque syntax mixed with static type checking and type inference, compiled down into blazingly fast executables.

I mean, look at this thing:

# A very basic HTTP server
require "http/server"

server = HTTP::Server.new(8080) do |context|
  context.response.content_type = "text/plain"
  context.response.print "Hello world, got #{context.request.path}!"
end

puts "Listening on http://127.0.0.1:8080"
server.listen

It does make you happy, doesn’t it?

We’ve been backing the Crystal project financially for quite some time now, with us already using it in several apps running in production, and with great stability and performance being our experiences thus far.

With a little more maturity in the ecosystem and cross-compilation support for Windows, it would definitely be among our top three recommandations when it comes to languages for implementing microservices and web application backends.

We definitely won’t stop using Ruby (or Python for that matter) for much of our development work just because of the performance profile, as the maturity, expressiveness, and elegance of the language and frameworks is invaluable in us being massively productive with the language, but it is nice to know that whatever the future holds for Ruby itself as a language and runtime, the best parts of the language and the spirit from its ecosystem can be enjoyed among its higher-performance brethren like Crystal and Elixir.


Looking for a software development partner? Then get in touch with us and discuss your needs. We can help you with web applications, master data systems, enterprise system integrations, smartphone and tablet app development, IoT architectures, blockchain technology, containerization (Docker and friends), and data science and machine learning projects.

Kontakt os