Why I hate lambdas (Re: Do any of you recommend Python as a firstprogramming language?)

Terry Reedy tjreedy at udel.edu
Sun Mar 23 17:29:14 EDT 2008


"Roy Smith" <roy at panix.com> wrote in message 
news:roy-40994D.13513423032008 at 70-1-84-166.area1.spcsdns.net...
| There is a fundamental disharmony in how functions and other objects are
| treated in Python.
[snip]

For scalars and collections, print object prints the value, which is the 
main part of the object, in a form close to (or equal to) how it is created 
in code.

For functions, classes, and modules, this would be awkward to impossible 
since the corresponding code is not part of the object and may be either 
bulky and slow to access, not accessible, or non-existent.  So these three 
get name attitributes as a substitute.  Function names are also used to 
improve tracebacks over 'function at line nnn'.

Perhaps for these types, print could (should?) instead print the first list 
of the doc string, if there is one.

Method objects inherit the name of the function they wrap.  Other internal 
types are left anonymous, but how could they get a name when there is no 
code to give them a name.

Yes, fundamentally different categories of types are (sensibly) treated 
differently with repect to definition and namespace names, but calling that 
'disharmony' depends on the listener.

| If we created lisp-like lambdas and bound them to names like we did with
| other types of objects, we wouldn't have that.

Correct.  Tracebacks would always instead of just occasionally be less 
useful as functions would always be identified only by file and line 
number, as today with lambda expression.

Terry Jan Reedy






More information about the Python-list mailing list