We love using Ruby On Rails at Netguru. We are one of the fastest growing Ruby on Rails consulting companies in the world.
It’s our framework of choice in most cases - we know its best and worst aspects, and we feel comfortable using it. That being said, we're aware that there are other Ruby frameworks worth looking at. Today we want to show you Hanami – an alternative to RoR.
Hanami is still quite a young framework - the stable 1.0 version was released a year ago and the updated version 1.3.1 was released on January 18th, 2019. With almost a year gone by we can consider this technology for any real -world scenarios without worries.
Ruby on Rails is a great framework with lots of features which makes building apps really easy and quick - at least at the beginning. But all of RoR’s features come in one package, which means costs in terms of memory and CPU consumption. Hanami, on the other hand, is much more flexible, and you can very easily select parts of the framework you need in your project. You can start with something very basic and add more features only when you need them.
It might come in handy when you are starting a new project and you know it will be quite simple or when you want to extend your application. It can also be easier to create a small separate service just for this feature instead of changing the existing codebase.
It's a well-known fact that building applications with Rails is fun at the beginning, but as the codebase grows, the default code structure proposed by Rails often becomes a source of frustration. This means that you will need to spend some time on code refactoring, or use a better code structure from the start. Hanami offers a different approach – which might look like overkill when you're building something really small – but will bring large benefits as soon as the codebase grows.
Hanami is worth considering if you have a feature-stable application but you're struggling with some performance issues or bugs because the code structure is so complicated.
When we are interested in a technology we look at the documentation first. If it's poor, we will probably stick with our current technology stack. This is not the case with Hanami: the documentation is really good, and there are also many great tutorials.
There is even a step-by-step guide on rewriting a complete application from Rails to Hanami. And when it comes to the community, there are already many ready-to-use libraries. On top of that, many solutions in Hanami are very similar to those that we know from Rails, so you won’t feel lost when you look at the code for the first time.
There is only one really important disadvantage of Hanami: it’s much less popular than Rails.
Ruby on Rails is the most popular web framework in the Ruby world, and it's hard to compete with that. Hanami has fewer ready-to-use libraries, tutorials, and other great resources – you can find them all in Rails though. The community is also smaller (but hey, it is growing!), so sometimes you will have to wait a bit longer for some answers. If that's important for you, or you're used to building applications quickly from ready-to-use blocks, Hanami shouldn’t be your first choice.
As the Hanami framework is still young in comparable terms it can be hard to find exact use cases to help make decisions - but there are other alternatives out there which might give you inspiration.
'The MVC's frameworks idea is to build one structure following the Model -> Controller -> View. Hanami follows the Model | Controller -> View -> Template. The result is an application more uncopled, following SOLID principles, and much cleaner.'
Even though we’re used to some technologies there will always be an alternative.
It’s good to know what is available in case you’re planning a new project, or if you are trying to do a complete overhaul on an existing one. As with any other framework, whether Hanami is a good fit for you will always depend on your individual case.
Before you get tied to one framework or another make a list of pros and cons and decide!
Feel free to use our list as a guide or contact us for advice today.