Log in

No account? Create an account
Random software stuff - Arvind Narayanan's journal [entries|archive|friends|userinfo]

Random software stuff [Jul. 27th, 2007|12:05 pm]
Arvind Narayanan
[Tags|, , ]

I love the "you can close this window now" dialog box in the ubuntu update manager. Tickles me for some reason I can't quite articulate. Reminds me of Arthur in the Hitchhiker's guide:
"I wonder what happens if I push this button" ... "Oh, a sign lit up saying 'Please don't push this button again!'"
There are a couple of good google tech talks by Guido van Rossum. Apparently many of the design issues that python 3000 will fix are consequences of decisions that were taken in the first few weeks or even days of the fledgling language, back in 1989. I can't quite imagine what it must be like to be in that position, to see your toy project snowball into this huge... thing. I also learned that classes in python started life as namespaces. That explains so much!

A lot of people hate lisp syntax. Usually it's the parentheses, but there is quite another reason that I hate it. Most often, I organize my program as a sequence of filters. I suspect most people do -- lisp certainly encourages it. This means that in the expression
(h (g (f list)))
f is the producer, h is the consumer and g is both. I don't know about you, but I'd much rather write that expression with the names of the functions in the same order as the data flow. The normal function call syntax inverts the data flow order. This makes programs hard to read. Bad bad bad.

Think of some other system with a producer-consumer paradigm that supports lazy evaluation. Shall we say Unix pipes? Think of the most common interface to it -- the shell. Shell pipe syntax! Sequence of filters! Bingo -- that's what lisp (and in fact, function invocation syntax in every language) should look like. (h (g (f list))) should instead be
list | f | g | h
Order in which they execute. Pleasing to the eyes.

It's easy to come up with intuitive syntax for when there are multiple arguments, let-bindings and so forth. Here's one example: (h (g (f list) a)) would become list | f | g x=a | h where x is the name of the second formal argument to g. Notice that this lets you specialize a function using any subset of its arguments, with no addition to the syntax!

The trouble with programming languages is that they are designed by people with no training in cognitive studies or usability, sciences that are typically derided by computer scientists. That's why whitespace indentation is such a huge win, despite drawing the instinctive contempt of programmers when they first encounter it.

[User Picture]From: haran
2007-07-28 12:24 am (UTC)

def filter(*args):
___r = args[0]
___for f in args[1:]: r = f(r)
___return r

I'm not familiar with lisp's syntax, but shouldn't it be possible to make that work (it has support for partial function applications, right - that will solve the problem of having the functions take arguments)?

I thought doing domain-specific sub-languages was all the rage in lisp?
Can't you get a syntactically clean implementation of the above?

(Reply) (Thread)
[User Picture]From: arvindn
2007-07-28 02:15 am (UTC)
Yeah, that'd probably work, but it gets real awkward real fast, and would probably break on more complex examples.

I'm sure it'd be cleaner in lisp. I've never seen anyone write code that way though.

Lisp totally has partial function application. It's just you always have to specify all the arguments, AFAIK, instead of just specifying the ones you want to fix.
(Reply) (Parent) (Thread)
[User Picture]From: haran
2007-07-28 02:31 am (UTC)

It's just you always have to specify all the arguments, AFAIK, instead of just specifying the ones you want to fix.

Seriously? How lame.
I'm surprised you can't just specify the first n arguments.

On a tangent,
Mochikit (javascript framework) has a nice partial function that allows you to partially apply functions with the first n arguments. Its incredibly useful especially given Javascript's (and Python's for that matter) weird scoping rules that bite you when you're trying to create closures in a loop.

(Reply) (Parent) (Thread)
From: t3rmin4t0r
2007-07-30 07:48 am (UTC)

trackback ...

... I wrote a 4-line class which lets me use the kind of shell pipe syntax - as long as I don't break any python operator precedence rules ...
(Reply) (Thread)
[User Picture]From: arvindn
2007-07-30 07:18 pm (UTC)

Re: trackback ...

Didn't realize you could to that. Very cool, thanks!
(Reply) (Parent) (Thread)