Wednesday, January 23, 2008

Per-post comment feeds

I've just changed the blogspot settings so that posts and comments are separate feeds. That seems to be how most of the cool kids do it these days. Updated: in addition to the per-post comments feeds, there's now a link for an all-comments feed at the bottom of the main page. I wound up hand-editing the blogger template to add that; surely there's a better way...?

Tuesday, January 22, 2008

Thoughts on Lisp: Things that other languages should take from Lisp

Things I like about lisp that haven't crossed over into enough mainstream languages yet:

  1. "Bignum" support: language-integers are logical-integers, not fixed-width bitfields. In Scheme and Common Lisp, by default you can't overflow an integer --- the language will dynamically expand the size of the representation as necessary. This guarantees numerical correctness, at the cost of some performance.

    In Common Lisp, you can force your code to use fixed-size numbers (fixnums) for efficiency. I like this overall system: the default is automatically "correct", but you can turn the knob toward performance in critical regions. This helps avoid embarrassing explosions.

    Ruby and Python, by default, treat language-integers as logical-integers. Java, C, C++, and Perl don't; you have to go out of your way to use a bignum class. The rest of the numeric tower is also nice to have, but far less essential to basic correctness.

  2. Optional type declarations (Common Lisp.) CL allows, but does not require, type declarations. The compiler can use these declarations to improve the speed of compiled code, and you only have to put them in the critical regions to get the performance benefit. The compiler can also use type declarations to perform compile-time typechecking. (Sadly, it isn't required to do this.) I like being able to have a blend of static and dynamic typing in the same programming language. Both have their places.

  3. Proper (unbounded) tail-recursion (Scheme.) If the last statement of a function, F, calls another function, G, there is no need to save space for F on the stack. In Scheme, such tail-recursion really doesn't reserve space. This lets you write tail-recursive algorithms that go arbitrarily deep, without worrying about running out of memory. The Scheme standard requires this to work. In most other languages, the stack space gets saved anyhow, as the language specifications don't forbid it.

  4. Methods with multiple-dispatch (Common Lisp.) In most languages, when a method is invoked, the first argument to that method determines which of several implementations is actually run. In the Common Lisp Object System, any or all of the calling arguments may be used to select the method implementation. There's a lot I don't like about CLOS (perhaps I'll go on at length in some future post), but multiple dispatch is a very handy hammer to have in the toolbox.

  5. Some Lisp implementations are fast. Unlike Ruby, Python, Perl, PHP, and JavaScript, both Common Lisp and Scheme have good native compilers.

  6. Syntactic simplicity (Scheme.) This is a positive view of "syntactic poverty," which I said I don't like in I'm giving Scheme this exception here because it is widely used in teaching. Syntactic simplicity gets students writing code faster than if they're trying to handle a bunch of ideosyncractic syntactic rules. And student code is reliably write-once, read-never-again. Of course, even MIT seems to be replacing Scheme with Python in the undergraduate EECS curriculum. I'm inclined to bow to the wisdom of the practicing teachers on this one. Or perhaps Python is another incarnation of syntactic simplicity.

Coming up next: I'm going to give the Lisp series a break for awhile. I've got some robotics stories I've been meaning to write up forever. Maybe I'll get around to them finally.

Friday, January 11, 2008

The limits of touch-screens

If a touch-screen is too big to wipe on your shirt sleeve, it's going to get too nasty to use. It's going to be too nasty even to sell, 'cause the floor-model in the shiny-shiny electronics store will be covered with greasy fingerprints.