Archive for the ‘Lisp’ Category

C++ Template Metaprogramming

Thursday, September 10th, 2009

I have not used C++ in many years. It was so long ago that templates, in the way they are used today, were not in C++ yet. I hope I never have to program in C++ again. That said, it’s interesting to know that C++ templates are so powerful that you can write a compile-time Lisp interpreter in them!

The following is from the notes at Amazon about the book “C++ Template Metaprogramming” by David Abrahams and Alexey Gurtovoy:

“In 1998 Dave had the privilege of attending a workshop in Generic Programming at Dagstuhl Castle in Germany. Near the end of the workshop, a very enthusiastic Kristof Czarnecki and Ullrich Eisenecker (of Generative Programming fame) passed out a few pages of C++ source code that they billed as a complete Lisp implementation built out of C++ templates. At the time it appeared to Dave to be nothing more than a curiosity, a charming but impractical hijacking of the template system to prove that you can write programs that execute at compile time. He never suspected that one day he would see a role for metaprogramming in most of his day-to-day programming jobs.”

Thanks for David Mankins for bringing this to my attention!

I recently learned about Python’s powerful metaprogramming techniques, from a talk by Adam Baratz of The Echonest. This was very impressive and I hope to find time to learn more.

What Programming Language Do People Speak Well Of?

Friday, September 4th, 2009

I usually don’t write blog entries that are merely pointers to someone else’s blog entries, but I’m making an exception this time. A blogger named Lukas Biewald, in a blog called/of Dolores Labs, wrote an entry called The Programming Language With The Happiest Users.

He measured Twitter “tweets” that mention certain programming languages, and ascertained which were positive. I’m particularly interested because Lisp came in second place.

Interpreting this as “the programming langauge with the happiest users” depends on several tacit assumptions that seem dubious at best.  We don’t know that the people writing these comments are actually users.  The number of tweets sent about a language is not uncorreleated with the langauge; I bet there are fewer COBOL programmers using Twitter than Perl programmers.  Not everybody tweets about how much they like or dislike their langauge as much as everybody else. He knows this and mentions some of these problems at the end of the post, so I’m not saying this to criticize him.

Yes, the title of the blog post is sort of misleading, but written to get the attention of readers.  I cannot criticize him for that either, since I do the same thing.  Sometimes it backfires; a lot of people seem to have seen my post named “Why Did M.I.T. Switch from Scheme to Python” without getting my points, which were (1) they didn’t make a high-level decision to switch languages, but rather this fell out as an end consequence of decisions that had nothing to do with languages, and (2) this is only for the freshman core courses, not the whole curriculum.

It’s hard to draw any hard and meaningful and useful conclusions from this research, but I still find it interesting and entertaining.

Programming with Concurrency

Monday, July 27th, 2009

New high-speed computers will have more and more cores as the years go by, and the ramp-up has started and is going very quickly.  To take advantage of those processors, some programs will need to use interesting (complicated and novel) concurrency.

But the history of concurrent software is littered with approaches that just turned out to be too hard to use, and the software was slow to develop and very hard to debug.  Now that we’re all in the same boat, how do we solve the software problem?

Many language designers think that the answer lies in pure (side-effect free) programming.  The best known, and quite practical, languages that are pure are Haskell and Erlang.

But many new languages are arriving based on the idea that you should use mostly side-effect-free code, and then when side-effects are needed, use transactions.  This is at least a trend if not a movement or revolution.

When Guy Steele came back from the JAOO Conference, I asked him for a quick report, and he sent me this (very slightly copy edited, used with Guy’s permission):

I was stunned by the end of the first day of JAOO 2008 when I realized that Anders Hejlsberg had given a plenary talk on C#, I had given a talk on Fortress, Bill Venners had given a talk on Scala, and Erik Meijer had given a talk on functional programming, and we had all delivered approximately the same message to this object-oriented crowd: the multicores are coming—no, they’re here—and the only plausible way to deal with them in the long run is to rein in the side effects inherent to the OO point of view and move as much as possible to a functional programming style with mostly-immutable data structures and implicit parallelism.

I am very excited by the new Clojure language, which is a dialect of Lisp based on exactly these same principles.  Rich Hickey apparently wasn’t at JAOO, but would have found friends there!

Normally I don’t try to learn a language unless I’m about to actually program in it.  But it’s worth learning a language when you pick up fundamental new ideas that might be helpful (or just interesting).  Haskell is like that (thanks, Alan Bawden, for letting me know).

If you might have to write highly-concurrent programs in the future, I recommend that you keep your eyes on all this.

Come to the European Common Lisp Meeting!

Tuesday, June 30th, 2009

The European Common Lisp Meeting will be in Hamburg, on the weekend of September 12 and 13, 2009.  I greatly enjoyed last year’s ECLM, in Amsterdam. It’s relaxed and gives you a lot of opportunity to meet great Lisp experts from all over the world. Arthur Lemmens and Edi Weitz did a superb job arranging for entertainment and space, and making sure everyone was happy.

I’m also looking forward to seeing Hamburg; I’ve never been there, and it sounds great.

I’m giving a talk entitled A Highly-Available Large-Scale Transaction Processing System in Common Lisp. It’s about the airline reservation system that we’re building at ITA Software, specifically about the issues involved in using Common Lisp, which is not widely thought of as being a language for writing large-scale transaction processing.

The lightning talks at the International Lisp Conference last March went so well that Edi and Arthur are trying out this format at the ECLM.  After the ILC, someone told me that at another sofware-related conference he had been to, the lightning talks fell flat: few people signed up to give talks, and they weren’t very good.  At the ILC, I thought they were nearly all great.  We learned about new tools, stories, and so on.  There was a great one about using Lisp in a Lisp-unfriendly world.  In a nutshell: if they force you to program in PERL, then run a PERL-coded Scheme interpreter and write in Scheme!  I anticipate more fun lightning talks in Hamburg!

So, I encourage you to join the fun!

The “Worse is Better” idea and the future of Lisp

Sunday, June 7th, 2009

The tag line for the International Lisp Conference 2009 was Lisp: The Next 50 Years.  I am very interested in the future of Lisp, and hope to be one of many participants in creating that future.  A widely-read paper from 1991 introduced the world to the phrase and philosophy called Worse is Better, and says that this philosophy should be used for the design of the next Lisp.  What does that mean, and what parts of the argument still apply and should guide us?

Richard Gabriel and Worse is Better

Richard P. Gabriel is a brilliant computer scientist, probably best known for his company Lucid, Inc., which produced an excellent Common Lisp implementation, and later developed a sophisticated software development environment called Energize.

He has written extensively about the process by which new technological ideas move to the marketplace.  His ideas about this are unique and very much worth learning.  The most well worked-out version of his thoughts are in his book, Patterns of Software, which I recommend highly.

His first essay on this topic is called Lisp: Good News, Bad News, How to Win Big, originally published in 1989.  It’s primarily about why the Lisp language was not succeeding as a vehicle for the delivery of practical applications.  It examines Lisp’s successes and apparent failures, and suggests how to improve things.  I find it very accurate and thoughtful, and holds up well over time.

The part that got the widest attention was Section 2.1, “The Rise of Worse is Better.”  Jamie Zawinsky, then of Lucid, forwarded this section to many people, and soon it was redistributed very widely.  It became, in effect, its own paper, generally known as Worse is Better.  Do a web search on that phrase and you’ll find all kinds of commentary.

It characterizes a school of design which Gabriel attributes to MIT and Stanford and calls “the right thing”.  He contrasts this with what he calls the “worse-is-better” philosophy, which he says “is only slightly different”.  Many commentators have oversimplified and overstressed the dichotomy, and so I strongly recommend that you read the original four points that he associates with each philosophy.  You’ll see that his characterization is careful and nuanced.

The phrase “Worse is Better” is rather over-the-top, and I think some people have misinterpreted the point because of that name.  I sympathize with Gabriel.  If you follow my own blog, you’ll see that I use somewhat provocative names for the articles, in order to attract readers.  Sometimes it backfires.  In my case, I used “Why Did M.I.T. Switch from Scheme to Python?” for an entry whose point was that the switch is not what’s important.  But perhaps since it was the title, people commented mostly on the language issue!  Oops.  Some of the commentary on Worse is Better gets confused and thinks the two philosophies are simple opposites, but it’s much more subtle than that.

Worse is Better contains a story, which starts: “Two famous people, one from MIT and another from Berkeley (but working on Unix) once met to discuss operating system issues.”  He wrote the story based on an oral account from me.  In fact, the “MIT guy” was me, and the “New Jersey guy” (from Berkeley; see the paper for why) was Bill Joy.

His account is basically right.  About the phrase “two famous people”, Bill Joy is far more famous than I am (see the current best-selling book, “Outliers”, for example).  Neither of us said “it takes a tough man to make a tender chicken” (a line from an old TV commercial), as far as I remember.  If you want to know about the issue that he spells “PC-loser-ing”, see the excellent 1989 paper PCLSRing: Keeping Process State Modular, by my friend Alan Bawden.  It has been described as “an unpublished but influential note by Bawden”, and has been widely cited.  (The general concept of PCLSR has to do with forcing a thread of execution to be X-consistent, for some level of abstraction X, even if the thread is operating below the level of X.)

Gabriel’s section ends: “But, one can conclude only that the Lisp community needs to seriously rethink its position on Lisp design. I will say more about this later.”

What does this mean for the future of Lisp?

The paper is about Lisp, but if we look carefully, it doesn’t bring the “worse is better” point to bear on Lisp very much.

Section 3.6, “The Next Lisp”, starts: “I think there will be a next Lisp. This Lisp must be carefully designed, using the principles for success we saw in worse-is-better….  The kernel should emphasize implementational simplicity, but not at the expense of interface simplicity. Where one conflicts with the other, the capability should be left out of the kernel.”

He goes on: “Some aspects of the extreme dynamism of Common Lisp should be reexamined, or at least the tradeoffs reconsidered.”  He gives an example of correct but undesirable Lisp code, in which a function redefines top-level functions.

It’s hard for a compiler to optimize code in the presence of this kind of runtime behavior.  There’s no need to write programs this way.  Lisp has better ways to do what this code fragment is trying to do, and any competent Common Lisp programmer knows that and knows the proper way.  Therefore, the next Lisp should consider omitting this capability.

Reducing extreme dynamism, way out at the edges, sounds promising, and should be considered carefully.  But this specific example is the only one he gives!

The rest of the section is about how to layer the implementation.  All of this is great, but it does not seem to have anything to do with “Worse is Better”!

The next section is “Help Applications Writers Win”, and clearly the right thing philosophy makes things better for application writers than the worse is better philosophy, all other things being equal.  The point of the paper is that all other things aren’t equal because the worse is better philosophy should help get the system done on time and help it spread.  But that’s just the overall thesis of the paper, not specific to Lisp at all.

Why does this paper spend so much time on the Worse is Better philosophy, when it bears so little on Lisp?

I’ll go out on a limb and speculate that this was very much on Gabriel’s mind at the time.  He felt it was relevant to Lisp because MIT/Stanford people were frustrated that Unix seemed to be ignoring lessons and techniques that had been developed, and widely used, over so many years.  He might even have been thinking of the competition between his own Lucid Lisp product and its competitors.  But I ought not put words in his mouth.

Gabriel later wrote much more about the Worse is Better philosophy.  He famously conducted a debate with himself, writing the other side under the pseudonym “Nickieben Bourbaki” (an allusion to Nicolas Bourbaki).  These include Worse is Better is Worse, Is Worse Really Better?, and even more.

What do you think: do the ideas in the Worse is Better series of papers bear on the question of the future of Lisp?  I’d appreciate if you’d take a look at Gabriel’s paper before answering!

P.S. Dept. of Fair Attribution: I borrowed some phrases of text from various Wikipedia articles.  Look here for more general discussions about the future of Lisp.