Language Commitment

Hugh Winkler: "S-expressions give Lisp powerful ways to build code in code. But writing programs using S-expressions seems cumbersome compared to Ruby's syntax. The syntax of Ruby shortens the code you have to write to do everyday tasks. It's like a domain specific language for, er, writing computer programs."

Here's Hugh's example in Python:

PEOPLE = [{'first':'scott', 'last':'guthrie', 'age':32},
              {'first':'susanne', 'last':'guthrie', 'age':32},
              {'first':'bill', 'last':'gates', 'age':50}]

def avg_age(lastname):
  people = [person for person in PEOPLE if person['last'] is lastname ]
  return sum([person['age'] for person in people]) / len(people)

Perfectly readable? Yes, if you know enough Python. And as much can be said for Hugh's Lisp/Ruby examples. For what it's worth, I don't think the Python, Lisp or Ruby examples are essentially more readable than the other. In terms of pure technical elegance, Lisp wins because it's has the more internally consistent syntax - which is arguably what marks out Lisp as being the most 'different' for these kinds of small examples. All those parens stop becoming a negative when you want to manipulate the language itself in a deeper way than either Ruby's open classes or Python metaclass hacking. [But if that was the main criterion, we'd all be using Lisp, and Ruby/Python would never have been invented.]

Here's Peter Norvig on Python: "Python can be seen as a dialect of Lisp with "traditional" syntax (what Lisp people call "infix" or "m-lisp" syntax). One message on comp.lang.python said "I never understood why LISP was a good idea until I started playing with python." Python supports all of Lisp's essential features except macros, and you don't miss macros all that much because it does have eval, and operator overloading, and regular expression parsing, so you can create custom languages that way."

I suspect DSLs, or what used to be called little languages, are a red-herring. DSLs are not a language commitment. I'd be inclined to look at what's fundamentally different and interesting with Ruby, be they transient issues such as the runtimes, unicode, decent libraries, and IDE support, or essential issues such as blocks, optional functional call parens, and open classes. Those are the things that are going to sway you to the language or away from it insofar as you're going to be committed to dealing with them.

Tags:

1 Comment


    I think we would all be using Lisp if Sun had put millions of dollars into building massive set of libraries, a fast byte code virtual machine and marketing it.

    Languages have been inching towards Lisp for decades so in a sense we are all on the road to using Lisp. I look forward to actually getting there.

    I cannot understand how the parens bother anyone. I like them. I think Lisp looks great sitting on the screen in my editor. Given the power the parens enable I don't think they would be a deal breaker even if I didn't like them.