What is different with Python ?

Roy Smith roy at panix.com
Mon Jun 13 07:53:03 EDT 2005


Andrea Griffini <agriff at tin.it> wrote:
> There's no way you will remember what is O(n),
> what O(1) and what is O(log(n)) among containers
> unless you roughly understand how it works.

People were thinking about algorithmic complexity before there was random 
access memory.  Back in the unit record equipment (i.e. punch card) days, 
people were working out the best ways to sort and merge decks of punch 
cards with the fewest trips through the sorting machine.  Likewise for data 
stored on magnetic tape.

I can certainly demonstrate algorithmic complexity without ever going 
deeper than the level of abstraction exposed by Python.  You can learn 
enough Python in an afternoon to write a bubble sort and start learning 
about O(2) behavior without even knowing what a memory address is.

Somebody mentioned that string addition in Python leads to O(2) behavior.  
Yes it does, but that's more an artifact of how Guido decided he wanted 
strings to work than anything fundamental about memory allocation.  He 
could have taken a different design path and made Python strings more like 
STL vectors, in which case string addition would be O(n).  Teaching that 
"string addition is O(2)" is not only needlessly confusing for somebody 
just starting out, it's also wrong (or at best, a specific case valid for 
one particular implementation).

And, BTW, I started out programming on a big HP desktop calculator 
(http://www.hpmuseum.org/hp9810.htm).  Next came BASIC.  Then Fortan and 
assembler on a pdp-10.  Then C, a couple of years later.  After that, I've 
lost track.  Some of the languages that taught me the most were ones that 
got very far away from the hardware.  NewtonScript was my first 
introduction to OOPL, and PostScript showed me that stack languages aren't 
just for calculators.  Lisp, of course, expanded my mind in ways that only 
Lisp can (the same could be said for many things I tried back in those 
days).  Even quirky HyperCard showed me a different way to think about 
programming.

I think it's probably just as important for a CS major to play with those 
mind-altering languages as it is to worry about bytes and pointers and 
memory locations.  But you can't start everywhere, and if you've got to 
start someplace, Python let's you concentrate on the real universal 
fundamentals of data structures, algorithms, and control flow without 
getting bogged down in details.



More information about the Python-list mailing list