Hacker News new | ask | show | jobs
by dudeinjapan 220 days ago
Yikes. This means that you’ll have 1000 micro-DSLs sprinkled all over your codebase, which will become unreadable and lead to confusion/accidents. Better to stick with good ol’ key-value labelling.
2 comments

This is a philosophy. One which many people that write Ruby subscribe to. The fundamental idea is: create a DSL that makes it very easy to implement your application. It is what made Rails different when it was created: it is a DSL that makes expressing web applications easy.

I don't know its history well enough, but it seems to originate from Lisp. PG wrote about it before [1].

It can result in code that is extremely easy to read and reason about. It can also be incredibly messy. I have seen lots of examples of both over the years.

It is the polar opposite of Go's philosophy (be explicit & favour predictability across all codebases over expressiveness).

[1]: https://paulgraham.com/progbot.html

If there is one DSL which is a central abstraction of one’s entire app, used in 100s of places—this is fine.

If there is a DSL such as Rails’ URL routing, which will be the same in every app—this is also fine.

When one makes 100s of micro-DSLs for object creation, that are only ever used in one or two places—this is pure madness.

Yeah, this is honestly the sort of thing I grew to hate in Ruby. It looks cute, but all it does is create more cruft. Good ol’ boring keys are just fine, expressive enough, and are very unlikely to cause problems. This feels like it’s attempting to solve a problem that does not exist.
The advantage is the amount of code minimized and not using a generic factory pattern. But that probably can be achieved with a bit less magic...
> this is honestly the sort of thing I grew to hate in Ruby

But nobody forces you to use a DSL such as rails, so I am not sure why ruby should be hated for this when it is a rails dev who does that.

The blog has much more to do with rails than ruby; such API design is really strange.

I don't think this design causes problems as such, but it is too verbose and way too ugly. To me it seems that they are just shuffling data structures around; that could even be solved via yaml files.

Working in a team means you are kind of forced to use what the team wants.

Of course you can try to convince them otherwise, or just be an asshole and mass-refactor to remove the DSLs.

But this kind of code is part of Ruby’s culture now.

The simple answer for anyone that doesn’t like this style is to leave Rails and Ruby for people who enjoy it.

It’s fine to hate it and want to distance yourself from it.