Writings of a techie wizard
Single Entry
Wed, 29 Jun 2011

The answer can be summed up in one sentence:

Not every data structure is a list.

Don't get me wrong: Lisp is a powerful engine for manipulating data structures. In fact, in one sense Python (like every other programming language) is just "syntactic sugar" for Lisp expressions; as Paul Graham put it, in Lisp "you express programs directly in the parse trees that get built behind the scenes when other languages are parsed." That ability gives you extra control and flexibility, but it comes at a price: since you're explicitly writing parse trees, you have to express all your data structures explicitly in terms of parse trees. Python may be just a layer of syntactic sugar over that, but syntactic sugar has uses.

In fact, ironic as it may seem, my reason for using Python instead of Lisp is really the same as one of the reasons for using Python instead of C: namely, that you don't have to build your data structures "by hand"! This will seem daft to those who believe that Lisp is a more powerful language, but consider the following code snippets in Lisp and Python:


(setf mydict (init-hash-table ("a" 1) ("b" 2)))


mydict = {"a": 1, "b": 2}

Obviously the Python version is shorter and easier to read (in fact, in the Lisps I'm somewhat familiar with, Common Lisp and GNU Scheme, there isn't even a way to initialize a hash table in one statement, so I'm actually assuming that someone has written an init-hash-table function to enable the above code to work, otherwise the Lisp version would be even longer and more complex). But the Python version also provides a valuable layer of abstraction that the Lisp version does not: it makes a dictionary, a mapping of keys to values, a built-in data structure, rather than one that I have to build "by hand". That may not seem like much for a single mapping with just two entries, but my Python code uses dicts all over the place, simply because it's such an easy and useful data structure. If I had to write init-hash-table and all those parentheses every time, I might not use them quite so much.

I know, I know: you just have to "get used" to reading Lisp and then it will seem easier, and writing all those parentheses and init-hash-table every time won't seem so bad once I've gotten enough practice. But why should I have to reprogram my brain to fit the language? The fact is that the abstraction I want is a dict, not a list that's been gerrymandered into something that can act like a dict. Programming languages are supposed to adjust to fit programmers, not the other way around.

Posted at 22:20   |   Category: rants   |   Tags: computers   |   Permalink
Wizard Projects
Site Links
Open Source Projects
dev release
dev release
dev release
dev release
dev release
dev release
dev release
dev release
dev release
dev release
dev release
dev release
dev release
dev release
Old Open Source Projects
Python Recipes
Fun Stuff
Shameless Plugs
Copyright © 2011-2015
by Peter A. Donis
All Rights Reserved