Sat, 29 Apr 2006

Intelib : WTF?

LISP is one of the grand daddies of the programming languages; the first implementation was written in 1962. The Wikipedia entry is an interesting read for anyone interested in programming languages.

In many ways, LISP was way ahead of its time and was vastly different from other high level languages of a similar era like C and FORTRAN. LISP was dynamically typed (like Perl, Python, Ruby etc) a decade before the the first implementation of Smalltalk, had garbage collection more than two decades before Java and had meta programming capabilities over three decades before templates were introduced to C++.

During the 1970s and 1980s, programing languages like C and FORTRAN would have seemed pretty primitive in comparison to LISP. So much so that in 1993, computer scientist Philip Greenspun came up with his Tenth Rule:

"Any sufficiently complicated C or Fortran program contains an ad hoc, informally-specified, bug-ridden, slow implementation of half of Common Lisp."

The Wikipedia entry cites the GTK+ GUI libraries (written in C) as a perfect example because these libraries contain their own internal implemention of "garbage collection, dynamic loading, object orientation, and even closures". All of these are features that already exist in LISP and many other high level languages.

Recently I came across something else that is a perfect example of Greenspun's Tenth Rule in action. Intelib is a GPLed library of C++ template and operator overloading hacks that allows the criminally insane to write inline LISP code in a C++ program.

From the Intelib web site the following LISP code:

  (defun isomorphic (tree1 tree2)
     (cond ((atom tree1) (atom tree2))
           ((atom tree2) NIL)
           (t (and (isomorphic (car tree1)
                               (car tree2))
                   (isomorphic (cdr tree1)
                               (cdr tree2))

can be inlined in C++ as:

  //       File isomorph.cpp
  #include "lisp/lisp.hpp"
  #include "lisp/lsymbol.hpp"
  #include "lfun_std.hpp"


  static LFunctionalSymbol <LFunctionDefun> DEFUN("DEFUN");
  static LFunctionalSymbol <LFunctionCond> COND("COND");
  static LFunctionalSymbol <LFunctionAtom> ATOM("ATOM");
  static LFunctionalSymbol <LFunctionAnd> AND("AND");
  static LFunctionalSymbol <LFunctionCar> CAR("CAR");
  static LFunctionalSymbol <LFunctionCdr> CDR("CDR");

  LListConstructor L;

  void LispInit_isomorphic() {
    static LSymbol TREE1("TREE1");
    static LSymbol TREE2("TREE2");

        (L|(L|ATOM, TREE1), (L|ATOM, TREE2)),
        (L|(L|ATOM, TREE2), NIL),
        (L|T, (L|AND,
          (L|ISOMORPHIC, (L|CAR, TREE1),
                         (L|CAR, TREE2)),
          (L|ISOMORPHIC, (L|CDR, TREE1),
                         (L|CDR, TREE2))
  //      end of file

Now I am one of many who think that C++ is an abomination of a language with way too many features fighting each other for supremacy. Similarly, as advanced and ground breaking as LISP was, it also had some major problems. The heavy use of parentheses makes LISP coding almost as big a pain in the neck as writing XML in a standard text editor.

To merge the worst features of C++ and LISP like Intelib, while technically amazing, is also a stunningly bad idea. When I first saw it, I was sure it was some sort of amazingly clever troll. Looking over the web page, I'm less sure. The author/s are even offering other licensing arrangements for people who would like to use Intelib but don't want to use it under the terms of the GPL.

Scary. Very, very SCARY!

Posted at: 12:25 | Category: WTF | Permalink