A Domain Specific Language For Writing Dirty Limericks

chromatic on 2007-07-27T16:31:04

I wrote a domain-specific language for writing dirty limericks. It looks a lot like English, but you have to prefix rhyming words with colons. Otherwise, it's a completely new language, so please read my weblog and buy my book and come to my conference talk about how awesome I am for doing what everyone does every day with English: use it as intended.

:There :once :was :a :programmer :of :Ruby...

Here's more joy on my least favorite subject Ruby programmers can talk about these days:

I meant to suggest in my previous post that the flaw was in me for no longer thinking in Perl when using Perl, though at the same time if Perl were to better support DSLs (domain specific languages) then I would have gotten a Get-Out-of-Jail-Free Card despite my mis-think. I hope that others reading this benefit from the clarification as well.

  Cosine Jeremiah, Knowing Ruby and Perl

Cosine, if you post yet another followup, please explain precisely what in the world you possibly mean by "better support DSLs" and perhaps even "DSL" in general.

Why do I ask this?

Cosine uses the example of Ruby's OO primitives and pervasive use of blocks to change the behavior of a Hash instance... and claims somehow that this makes a building block of a domain-specific language.

This baffles me.

When you find yourself starting to think "HAI I JUST WRITEDS A DSLS!!!", stop. You are not a Big Man who has performed the Manly Deed Akin to Dragon-Slaying and Princess Rescuing by defining your own language which just magically happens to have exactly the same syntax as Ruby and the same semantics of Ruby. YOU JUST CHOSE IDENTIFIER NAMES THAT MADE SENSE FOR YOUR PROBLEM DOMAIN.

Now that is a reasonable and honorable and well-maintainable thing to do, and I congratulate all of the Ruby developers (and Perl developer and Java developers and PHP developers and C developers and Haskell developers and you get the picture that just about every language that allows you to choose meaningful identifiers supports choosing meaningful identifiers while keeping the syntax and semantics of the language unchanged) for that.

Now can we all stop this wankery over "My language lets me do made-up thing that doesn't actually have any defining characteristics that I can't figure out how to do in your language" and actually have a conversation about how to write maintainable programs and devise good APIs?


Lispy view

jjore on 2007-07-27T17:52:28

Considering this, if Lisp claims to be great at doing DSLs, I suppose it is because it has macros to allow custom flow control. The rest is all just identifiers.

I've heard that the Ruby folks like to inject methods into base classes to let them talk about collections using their domain's terminology as methods directly on the data. This seems to just be another riff on derived types but perhaps without bothering to actually declare the new type. I guess the idea is instead of making your new type be a specialization of the generic type. Seems dodgy to me.

Re:Lispy view

chromatic on 2007-07-27T17:57:38

Considering this, if Lisp claims to be great at doing DSLs, I suppose it is because it has macros to allow custom flow control. The rest is all just identifiers.

Lisp is the Henry Ford of language design: you can have any syntax and semantics you want, as long as they're s-expressions.

(You could generalize that to internal DSLs too. I'm just waiting for the right time to show all of the "HAI I WRITED U A DSL!!!!!" kiddies the attributes of P5NCI or source filters in Perl.)

No Symbols Needed

djberg96 on 2007-07-27T21:57:16

There once was a programmer of Ruby
The above is perfectly legal Ruby code.

Re:No Symbols Needed

chromatic on 2007-07-28T00:10:41

It's also valid Perl code, so obviously it can't be a DSL. (Psst, your roots are showing.)

Re:No Symbols Needed

Aristotle on 2007-07-28T01:14:21

“I know it’s weird, but it does make it easier to write poetry in perl. :-)” —Larry Wall

Re:No Symbols Needed

djberg96 on 2007-07-28T16:48:51

Says who? That's never been a condition of a DSL.

Re:No Symbols Needed

chromatic on 2007-07-28T17:48:39

However, Perl is not really capable of DSLs...

  Cosine Jeremiah, Back to Perl.

You and I discussed that very phrase in my previous journal entry.

heh, very funny

rjbs on 2007-07-27T22:00:00

...but seriously, when is Perl getting better metaprogramming and DSL support? It doesn't even have symbols or procs, so you can't create custom yield types or assignment methods, which are all vital to any good domain solution.

I really want a Perl way to strip the cuss words from bbmarkup comments in my blog, but without a DSL for the task, I'm going to have to use Ruby. Or maybe Erlang, I hear that's hot now, too.

External Reply

cosine on 2007-08-05T18:00:52

I've replied to this posting here: http://www.cosine.org/2007/08/05/domain-specific-languages/

Re:External Reply

chromatic on 2007-08-05T23:54:56

I appreciate the reply, but you still didn't answer the question. What is a DSL?

"A little language that you can run through your host language's eval" is not an acceptable answer, because the only thing you can successfully run through your host language's unmodified eval is precisely that language itself.

If that's the case, then your statement that "Ruby is better at writing DSLs" is particularly meaningless, because it simplifies to "Ruby is better at writing Ruby code that the Ruby interpreter can interpret than Perl is", which is a tautology.

I don't think that's your point... is it?