Python's simplicity philosophy

Douglas Alan nessus at mit.edu
Wed Nov 12 17:34:10 EST 2003


"Andrew Dalke" <adalke at mindspring.com> writes:

> Me:

>> > But I well knew what 'sum' did.

> Douglas Alan
>> How's that?  I've never used a programming language that has sum() in
>> it.

> 1) From Microsoft Multiplan (a pre-Excel spreadsheet).  That
>   was one of its functions, which I used to help my Mom manage
>   her cheese co-op accounts in ... 1985?

Okay, well I can certainly see that a spreadsheet program should have
a built-in sum() function, since that's about 50% of what spreadsheets
do!  But general-purpose programming languages rarely have it.

>> I wouldn't even think to look in the manual for a function that adds up
>> a sequence of numbers, since such a function is so uncommon and
>> special-purpose.

> Uncommon?  Here's two pre-CS 101 assignments that use
> exactly that idea:
>   - make a computerized grade book (A=4.0, B=3.0, etc.) which
>       can give the grade point average
>   - make a program to compute the current balance of a bank
>       account given the initial amount and

I'm not saying that it's uncommon to want to sum a sequence of numbers
(though it's not all that common, either, for most typical programming
tasks) -- just that it's uncommon to build into the language a special
function to do it.  reduce(+, seq) apply(+, seq) are much more common,
since reduce and/or apply can do the job fine and are more general.
Or just a good old-fashioned loop.

>> It's irrelevant whether or not many people have received poor CS
>> educations -- there are many people who haven't.  These people should
>> be pleased to find reduce() in Python.  And the people who received
>> poor or no CS educations can learn reduce() in under a minute and
>> should be happy to have been introduced to a cool and useful concept!

> Actually, your claim is 'anyone can be explained reduce() in 10 seconds' ;)

Now you want consistency from me?  Boy, you ask a lot!

Besides, 10 seconds is under a minute, is it not?

Also, I said it could be explained in 10 seconds.  Perhaps it takes a
minute to learn because one would need the other 50 seconds for it to
sink in.

> I tell you this. Your estimate is completely off-base.  Reduce is
> more difficult to understand than sum.  It requires knowing that
> functions can be passed around.

Something that anyone learning the language should learn by the time
they need a special-purpose summing function!  Before then, they can
use a loop.  They need the practice anyway.

> That is non-trivial to most, based on my experience in explaining it
> to other people (which for the most part have been computational
> physicists, chemists, and biologists).

I find this truly hard to believe.  APL was a favorite among
physicists who worked at John's Hopkins Applied Physics Laboratory
where I lived for a year when I was in high school, and you wouldn't
survive five minutes in APL without being able to grok this kind of
thing.

> It may be different with the people you hang around -- your email
> address says 'mit.edu' which is one of the *few* places in the world
> which teach Scheme as the intro language for undergrads, so you
> already have a strong sampling bias.

Yeah, and using Scheme was the *right* way to teach CS-101, dangit!
But, like I said, I was taught APL in high-school in MD, and no one
seemed troubled by reduce-like things, so it was hardly just an MIT
thing.  In fact, people seemed to like reduce() and friends -- people
seemed to think it was a much more fun way to program, rather than
using boring ol' loops.

> (I acknowledge my own sampling bias from observing people in
> computational sciences.  I hazard to guess that I know more of those
> people than you do people who have studied computer science.)

Hmm, well I work for X-ray astronomers.  Perhaps I should take a
poll.

|>oug




More information about the Python-list mailing list