Express What, not How.
Raffael Cavallaro
raffaelcavallaro at junk.mail.me.not.mac.com
Thu Oct 16 20:54:53 EDT 2003
In article <3f8f0bca.425450585 at news.blueyonder.co.uk>,
alan.gauld at btinternet.com (Alan Gauld) wrote:
> In the general case I agree completely but a blanket statement
> that it is always true is absurd. There are many cases when a
> programmer is dealing with issues that simply don't arise in the
> human scenario. Anonymous functions are often used in
> scenarios where a name is meaningless.
And in those cases, anonymous functions are perfectly appropriate.
However, when dealing with the existing abstractions of the problem
domain, named functions and macros are superior. I contend that a great
deal more code should be dealing with the existing abstractions of the
problem domain than is currently the norm. (Part of this is premature
optimization - Programmers are reluctant to break code into smaller
named units for fear that the additional code and function calls will be
more computationally costly.) Remember that mathematics, string
manipulation, network protocols, etc., are all well understood problem
domains with _preexisting_named_abstractions_. These named abstractions
are what we should be thinking and programming in, not the primitives of
whatever language we happen to be using, nor even in anonymous
functional abstractions.
In addition, even if the programmer finds some novel way, only possible
in a machine implementation, to express a solution, our ability to think
clearly about that process is greatly aided by giving it a _name_. E.g.,
it is much easier to think about different sorting methods (bubble sort,
quicksort, etc.) by refering to them by name, than it is to have to look
at an implementation of them every time we wish to refer to them.
Naming is a fundamental step in building abstraction. Anonymous
functions, keep us trapped at the level of abstraction at which they are
defined. If we wish to reuse them, we must reiterate them, because we
can't simply refer to them by name. Why not simply name them, and use
the names? This is, after all, how people have been communicating
abstractions since the dawn of spoken language.
More information about the Python-list
mailing list