a lot of time reverse engineering some 34-GitHub-star gem’s meta programming” • “I know this is often an unpopular opinion, but I've grown to hate DSL's. They are almost NEVER good, solve the wrong problem, and generally badly.” • “Most of the time, though, if I see a gem with a DSL, I try to fi nd something else and only use the DSL based gem when its absolutely necessary.”
method call • `describe(‘description’)` doesn’t look like DSL, more programs • Block • It structures DSL with variety of ways, and `do~end` doesn’t interrupt our reading, `{}` style is even better • Less restrictions of naming • `if` option works, `update!` and `updated?` work
from DSL name • It’s a “language”, so it’s useless unless we all know what it means • It does too many things • It involves Model, View and Controller • Limited customizability • Hard-to-remember options, still not possible for full customization
happens from DSL name • `crud` de fi nes 7 actions, maybe? Or, maybe 4? • It does too many things • It creates controllers and views • Limited customizability • How to de fi ne custom views or actions?
Predictable and understandable • `attributes` declaring “attributes” for the object • `association` and `nested` are straightforward • `root_key` de fi nes a root key • Each DSL has one thing to do • Easy-to-understand options
• Usually one word or a short phrase, such as “ JSON serialization” • isolated • It doesn't affect other domains in a complex way • self-contained • You don’t have to know other things than the domain
`if` option instead of `conditional_attributes` method • `if` option is intuitive, not worth adding another DSL method • Alba provides `nested` method instead of `nested` option • `nested` option didn’t make sense (at least to me) • `if` option is applied to `attributes`, `attribute` and `association` • Inference works, easy to remember
and think again about whether it’s a simple, isolated and self- contained domain 1. If the domain is too complex or intricate, just use normal code 2. Keep each DSL method simple and let them do one thing well 1. Pick the right word that’s intuitive, readable and understandable 3. Provide options so that it’s fl exible enough to customize 1. Options also should be intuitive
preferable • “association” is better than “de fi ne_association” • Do not use self-invented word unless it’s a ubiquitous language • Users of the DSL must understand it • Verbs/nouns for DSL methods, adverbs/adjectives for options • `attributes :some, if: …`, `has_many :books, through: …`