Express What, not How.

Marcin 'Qrczak' Kowalczyk qrczak at knm.org.pl
Tue Oct 14 19:19:17 EDT 2003


On Tue, 14 Oct 2003 22:09:44 +0000, Raffael Cavallaro wrote:

> A theme of this whole thread is the difference between writing _what_ 
> something does, and _how_ it does it. The higher up the ladder of 
> abstraction we go, the more we want to express _what_ is being done. We 
> leave the _how_ defined elsewhere, to be consulted only as needed.

Sometimes a function is so simple that its body is more clear than any
name. A name is an extra level of indirection. You must follow it to be
100% sure what the function means, or to understand what does it really
mean that it does what it's named after. The code also gets longer - not
only more verbose but the structure of the code gets more complex with
more interdependent parts. When you have lots of short functions, it's
harder to find them. There are many names to invent for the writer and
many names to rememner for a reader. Function headers are administrative
stuff, it's harder to find real code among abstractions being introduced
and used.

Why do you insist on naming *functions*? You could equally well say that
every list should be named, so you would see its purpose rather than its
contents. Perhaps every number should be named, so you can see what it
represents rather than its value. You could say that each statement of
a compound statement should be moved to a separate function, so you can
see what it does by its name, not how it does it by its contents. It's
all equally absurd.

A program should balance named and unnamed objects. Both are useful,
there is a continuum between cases where one or the other is more clear
and it's subjective in border cases, but there is place for unnamed
functions - they are not that special. Most high level languages have
anonymous functions for a reason.

-- 
   __("<         Marcin Kowalczyk
   \__/       qrczak at knm.org.pl
    ^^     http://qrnik.knm.org.pl/~qrczak/





More information about the Python-list mailing list