Hacker News
Hanami 3.0: In Full Bloom
pclowes
|next
[-]
I still don't quite understand what it does all that differently from Rails? There are plenty of comments that are along the lines of > "Hanami brings is an intentional and well-reasoned architecture that supports building maintainable applications. It has taste" (posted below)
But concretely what does that mean? Their docs call out ways to avoid common rails anti-patterns and I agree with most of their opinions but you don't _have_ to write bad code in rails just because a lot of others have.
Having seen Rails deprecations at multiple large well known tech cos I appreciate the sentiment of an "architecture that grows with you" but I would say the driver behind those migrations wasn't so much the framework as the extreme flexibility of the code and what that produces with thousands of developers over 10+ years.
I don't see how any architecture of Hanami prevents that.
cllns_ruby
|root
|parent
[-]
We re-did our homepage recently, and we should make these things clearer. They're legitimate concerns and questions. We agree you don't have to write bad code in Rails, and we don't pretend that we can prevent bad code in Hanami. Instead we give application builders the tools to architect their applications in the way they desire. Really what we're doing is building an *option* for building Ruby apps that may speak better to some people. If you're completely happy with Rails then there's no reason to change. Still, you may learn something that'll help you build Rails apps by seeing how we do things. Additionally, it's completely modular: you can pull parts of Hanami into a Rails app. The most popular one people pull into Rails apps is dry-validation [1]
Some concrete differences:
- We have small, simple API's. Rails core classes have hundreds of methods for convenience, not to mention dozens of core extensions (a.k.a. monkey patches) to base Ruby classes. We prefer small, narrowly focused classes over large ones with many responsibilities.
- We have a dependency injection framework dry-system [2] included by default. This lets you write `include Deps["repos.article_repo"] to get an automatically instantiated (and now memoized!) `Repos::ArticleRepo.new` within your class. This makes dependencies trivial to stub out, and it also declares your dependencies in a single place, instead of littering constants throughout your code.
- We have sub-applications called Slices. Similar to Rails Engines but well... good, since they're a first-class concept that we encourage. Importantly, they're independently deployable. You can export and import components across slices, too. We can't tell you how to slice up your application, but we give you the tools to decide for yourself.
pclowes
|root
|parent
[-]
A long time ago I had a "Component Based Rails Application (CBRA)" using engines as the domain boundary. It was unpleasant because it just moved pain points into unfamiliar places. The slices approach is very interesting.
Overall I like dry-rb.
If I find myself on a ruby project again I will investigate more thoroughly!
cllns_ruby
|root
|parent
[-]
I tried out Rails Engines on a couple projects, with such high hopes and ran into issue after issue. Sure it's theoretically possible to build whatever you want with Rails, but in practice it's infeasible. Some people have experimented with arbitrarily nesting Hanami slices too and had success. It's not something we're focusing efforts on because it's rather niche and get inherently complicated but it's possible.
Modularity is such an important part of large software projects and Rails doesn't give you any tools for it (and Ruby doesn't help either). Packwerk was an attempt to constraint Rails, with limited success: https://shopify.engineering/a-packwerk-retrospective.
pclowes
|root
|parent
[-]
Agree on the engines, you’re just fighting the framework the whole way.
Coincidentally working on modularity approaches for a different type of monolith https://viaduct.airbnb.tech/ (time is a flat circle etc. etc.)
JustSkyfall
|next
|previous
[-]
I have been using Rails 8 for the past few months on a work project, but the Hanakai ecosystem looks really, really interesting.
My one question would be whether or not Hanakai supports Inertia or Svelte views - we've been moving away from ERB recently, which has made it much easier to write interactive code due to the ecosystem, and I'd rather not throw that DX away!
cllns_ruby
|root
|parent
[-]
Hanami doesn't have any specific Inertia or Svelte specific integrations, but our view layer (and assets layer) is very flexible so it's certainly possible. It's worth investigating. If you try it out, let us know what you learn on our forum https://discourse.hanakai.org/
swe_dima
|next
|previous
[-]
cllns_ruby
|root
|parent
|next
[-]
Rom has some other advantages, like not needing a 1-to-1 mapping between tables/columns to models/attributes. For example, you could have a `users` table that maps to Profile and Account structs. Profile could include a `bio` whereas Account version could have the email, ensuring data doesn't leak beyond what's needed. They're two different use-cases for the same data, so should be modeled separately. This also lets you work with DB's where you don't control the schema (owned by other teams or legacy DB's): you can map the data into the structure you need for your app, instead of carrying around irrelevant attributes.
nine_k
|root
|parent
|previous
[-]
https://web-frameworks-benchmark.netlify.app/result?asc=0&f=...
rahil627
|next
|previous
[-]
i'm glad it's built from little composable gems (unlike rails). I'll def check out the dry-rb stuff for some ideas. :) Ruby is so cool.. often leads people to make over-engineered, "clean" design solutions, but it's so easy to read and learn from, so modular, i feel i can quickly make the choice/decision to add a tiny abstraction lib or more likely DIY something even more simple, leading to near zero deps. <3 ruby!
itsdesmond
|next
|previous
[-]
I really do hope ROM-rb, the not-orm Hanami uses, gets some development love as a consequence of this more formal merger. It’s a rad tool with enough rough edges that I had to switch away from it when launching a product a few years ago.
paozac
|next
|previous
[-]
vidugavia
|root
|parent
|next
[-]
itsdesmond
|root
|parent
|next
|previous
[-]
xswhiskey
|next
|previous
[-]
Love the work though; having beautifully crafted options like Hanami around is a joy.
cllns_ruby
|root
|parent
[-]
poszlem
|next
|previous
[-]
shoqr
|root
|parent
|next
[-]
When I was working at a software house, we had a client with a Hanami app (version 1). It was one of the best-engineered apps I’ve worked on - much better than 90% of the Rails apps we were working with at the time.
The only thing I missed was better Dry.rb documentation.
Hanami follows very good design patterns, useful for bigger applications. You may not see the value immediately with simple 5 minute blog app but over time, when the app grows, the abstraction layers will pay off.
cllns_ruby
|root
|parent
|previous
[-]
I'm confident you've also ran into large messy Rails apps too :)