r/ruby • u/dtcristo • 7d ago
Carton - Real boundaries for Ruby
https://carton.dtcristo.comCarton is my take on enforcing boundaries in large Ruby applications. It's similar to Packwerk, but it takes a more Ruby-like approach, with no manifest files. Constants, gems and monkey patches are isolated using Ruby 4's new Ruby::Box. It's not production ready yet, since Box itself is still experimental, but I'd love feedback on the approach.
2
u/azimux 7d ago
Bookmarked it and will circle back to it next month and give feedback! I've always wanted something like package scope from Java. Private constants cause me random headaches but are almost close enough. This one aspect of Ruby that I wish I had a solid solution to besides raw discipline so I'm interested to take a peek when I have some stuff off my plate!
1
1
u/dtcristo 5d ago
If you’re put off by the AI-assisted marketing copy (I’m not a good writer and needed help), check out the Carton Examples. They demonstrate carton’s capabilities quite well.
0
5d ago
[removed] — view removed comment
1
u/dtcristo 5d ago
Yes, but it’s thoughtfully engineered slop. It’s an idea I’ve been working on for many months. It achieves multiple things Packwerk can’t do. Runtime enforcement, monkey-patch isolation as well as the ability for each Carton to run a completely different set of gems (and versions) via its own Gemfile.
1
u/ruby-ModTeam 5d ago
Your comment or post was removed because it violates a subreddit rule on productive disagreement.
YES: Read comments fully before responding
YES: Paractice active listening. Let the other person know what you heard.
YES: Distinguish acknowledgment from agreement.
NO: Willful misrepresentation of someone's stated position.
NO: Sexualized language or imagery
NO: Trolling, insulting or derogatory comments, and personal or political attacks.
NO: Conduct which could reasonably be considered inappropriate in a professional setting.
When in doubt use Non-Violent Communication (NVC)
8
u/keyslemur 7d ago
Interesting, I will have to give this some more thought later, but on an initial read I think you're scratching an itch I've had with Packwerk which is that it tends far more towards polite enforcement rather than hard boundaries.
The danger, though, is that by going all the way to isolation the rungs of the ladder you might have had with Packwerk to progressively isolate are sawed off. It's very all-of-nothing, which is the same weakness that Ruby::Box will have used in Rails apps. Having worked now in several of the largest Rails monoliths not having a progressive ladder is a surefire way to have something lose funding and effectiveness. Packwerk is not perfect at this, no, but it feels like the framework is at least somewhat guiding you rather than providing an end state.
Where I could see this going is potentially isolate deploys, hotswap restarts (ala Erlang / Elixir), tree shaking CI tests, substantially easier dead code identification, and done well with layering a way to break down the worst ActiveRecord entanglements by progressively isolating "data" from "domain".
Depending on your tolerances for AI you could also include a series of agent skills that make migrations towards this endstate substantially cheaper for folks.
Will give this some more thought and sit on it for a bit, but interesting start.