Hacker News new | ask | show | jobs
by matthewmacleod 4476 days ago
Why would you do this?

If you're operating at the level where you need this level of indirection, then you should be looking at SOA anyway. Rails is not an appropriate platform, regardless of how much architecture you add to it.

If you're not operating there, then you are introducing complexity for no reason, and failing to take advantage of the features that Rails offers.

2 comments

Well Rails is a solid full-stack framework that is fairly modular, and of course ruby is extremely flexible in the architectural choices it allows, so it's very easy to take Rails in different directions by instituting your own conventions. It's probably easier to do this then to either pick a minimalist framework like Sinatra and build everything up from scratch, or find another language with a framework that suits your exact preferences.

I totally agree that Rails defaults hit a certain sweet spot. Putting a bit of logic in the controllers is fine in most apps, ActiveRecord is intended to mix persistence and business logic because many models aren't complex enough to merit separating them. Starting with a Hexagonal approach may well be premature optimization. I get it.

But lets be careful not to throw the baby out with the bath water. Rails intelligent defaults do have a tendency to leave a vacuum for apps reaching a certain level of complexity. That doesn't mean Rails isn't still useful, but just that it becomes inelegant when you don't have any conventions to deal with this and start hacking ad-hoc solutions into your codebase. I have a sneaking suspicion that partially this is inevitable in any living codebase, and that a complex system almost by definition can not be consistent and elegant since it is inevitably built over time under changing conditions. But in any case, I think Rails is a perfectly good place to experiment with ideas for managing complexity in a sizable app.

Having the indirection there allows you to take the Rails features you want with your boundary clearly defining which ones you depend on.

You could start with Rails, get ActiveRecord querying, migrations and template rendering for free and then maybe swap it out for Sinatra and the Sequel gem (I have actually done this).

Knowing your where your dependencies and technical debts are is very empowering.

What does hexagonal mean?
It's a reference to Alistair Cockburn's "Ports and Adapters" pattern, also called "Hexagonal Architecture".[1] The only reason I ever heard of it is that it was mentioned in the book "Growing Object-Oriented Software, Guided by Tests", by Steve Freeman and Nat Pryce (a good book in my opinion).

[1] http://alistair.cockburn.us/Hexagonal+architecture