Express What, not How.

Raffael Cavallaro raffael at mediaone.net
Sun Oct 19 01:11:08 EDT 2003


Ken Shan <ken at digitas.harvard.edu> wrote in message news:<bmq7mh$q75$1 at news.fas.harvard.edu>...

> But in the style of programming that you advocate, as I understand
> it, one does not need to give a name to function application from the
> problem domain before using it.

No, one doesn't, as long as that function application is the one place
where the implementation of that bit of functionality needs to be
expressed.

However, if one is using that bit of functionality elsewhere, then it
only constitutes information overload to re-express the implementation
of that functionality yet again in that location. In such a case, that
function application should be named in the one place it is necessary
to express its implementation, and the named version used elsewhere.

Again, it comes down to uniqueness and necessity of exposition. If it
is only going to be expressed once, and there is no loss of clarity,
then use an anonymous function. In this sense anonymous functions are
no different than using the built-ins or primitives of the language.
If this is  the place where this bit of functionality needs to be
defined, then, by all means, use anonymous functions to express that
implementation if it is easier.

But if that is not the one and only place where that bit of
functionality is used, then name it. If that is not the one and only
place where that functionality needs to be defined, then don't repeat
the implementation in a half dozen places. Implement it once, name it,
and use the name elsewhere.




More information about the Python-list mailing list