Express What, not How.

Marcin 'Qrczak' Kowalczyk qrczak at knm.org.pl
Wed Oct 15 04:18:49 EDT 2003


On Wed, 15 Oct 2003 00:41:28 +0000, Raffael Cavallaro wrote:

> Your argument is based on the assumption that whenever people express 
> _what_ a function does, they do so badly, with an inappropriate name.

Sometimes there is no name which is more clear than the definition.

A random example from OCaml source:
   if List.exists (fun q -> q.pat_loc = p.pat_loc) ps2 then ...

Would you write it like this? Please fill the appropriate <name>:
   let <name> q = q.pat_loc = p.pat_loc in
   if List.exists <name> ps2 then ...

Note that the function must be written here because it uses p which is
local, unless p was moved to its parameters and partially applied here
(this technique works for OCaml because of curring, it won't work for Lisp
or Scheme).

>> The code also gets longer 
> 
> No, it gets shorter, because you don't repeat your use of the same 
> abstraction over and over.

If it's used only once then the code is longer - see above.

>> 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.
> 
> Which is why names should be descriptive.

Great, many long names :-)

>> 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.
> 
> I think this concept is called variable bindings ;^)

I don't say I don't use variables. I say I don't use variables for *every*
subexpression. And sure I do use named functions, but not every function
deserves to be named.

> In the Smalltalk community the rule of thumb is that if a method body
> gets to be more than a few lines, you've failed to break it down into
> smaller abstractions (i.e., methods).

Hmm, Smalltalk blocks are anonymous functions. Do you reject Smalltalk
blocks too? :-)

> Yes, but they should live inside the bodies of named functions. Not lie
> exposed in the middle of higher level abstractions. Please also see my
> reply to Joe Marshall/Prunesquallor a few posts up in this thread.

You contradict yourself. First you say that "any anonymous function syntax
is undesirable", and they you accept anonymous functions in the middle of
higher level abstractions.

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





More information about the Python-list mailing list