Writings of a techie wizard
|
Indexes
Categories
Tags
computers (35)
economics (5) education (3) fantasy (3) history (5) info (8) movies (3) politics (40) science (8) Archives
2015‑Jan (1)
2014‑Sep (2) 2014‑Jul (1) 2014‑Jun (1) 2014‑May (1) 2014‑Apr (2) 2014‑Mar (2) 2014‑Jan (1) 2013‑Nov (1) 2013‑Oct (1) 2013‑Sep (2) 2013‑Aug (2) 2013‑Jun (1) 2013‑Apr (1) 2013‑Mar (1) 2013‑Feb (1) 2013‑Jan (2) 2012‑Dec (3) 2012‑Nov (2) 2012‑Oct (1) 2012‑Sep (3) 2012‑Aug (1) 2012‑Jul (1) 2012‑Jun (1) 2012‑Apr (2) 2012‑Mar (2) 2012‑Feb (1) 2012‑Jan (2) 2011‑Dec (1) 2011‑Nov (3) 2011‑Oct (2) 2011‑Sep (4) 2011‑Aug (6) 2011‑Jul (7) 2011‑Jun (8) |
Single Entry
Wed, 29 Jun 2011
The answer can be summed up in one sentence:
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: Lisp: (setf mydict (init-hash-table ("a" 1) ("b" 2))) Python: 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. |
Wizard Projects
Site Links
Open Source Projects
Old Open Source Projects
Python Recipes
Fun Stuff
Shameless Plugs
Copyright © 2011-2015
by Peter A. Donis All Rights Reserved |