3 ms·
As much as I don't really like the "DSL" terminology for anything less than a true language with a parser and AST of its own, the advantage of the Ruby-esque "D
by jerf 16y ago
As much as I don't really like the "DSL" terminology for anything less than a true language with a parser and AST of its own, the advantage of the Ruby-esque "DSL"/library-with-carefully-chosen-name-conventions is that you are starting from the base of a known-working language. I have a "DSL" I wrote at work for decorating functions with various metadata and recurring bits of functionality like permissions checking in Perl for work, but because it's just not-really-even-glorified Perl I still have the full power of Perl to do things like programmatically generate these functions. Using a recurring set of decorations is as easy as sticking them in a bog-standard Perl array and just passing them as bog-standard arguments in the right place.
It's tempting to replace your language entirely and compile down to something else, but IMHO this sort of thing shows that's a very dangerous play that generally succeeds big or fails big, usually the latter. Incremental expansion of an existing language, even with something as powerful as a syntax preprocessor (that ideally compiles to results that are themselves manipulable language constructs like closures or simple values passed in an idiomatic way), is generally the way to go; most of the win, hardly any of the risk. Something like StratifiedJS or something, if I understand it properly, adding meaningful additional syntax without trying to be its own independent language: http://onilabs.com/stratifiedjs http://onilabs.com/stratifiedjs Or, from the sounds of it, the way this language ultimately went.
Javascript may not be quite as slick as Ruby, but, well, to be honest I think Ruby partisans really oversell the value of being able to drop a few parentheses out of your code, and while the block syntax may be nicer JS still has relatively decent closures.