Alex Martelli wrote: > I think it's reasonable to make a name a part of functions, classes and > modules because they may often be involved in tracebacks (in case of > uncaught errors): to me, it makes sense to let an error-diagnosing > tracebacks display packages, modules, classes and functions/methods > involved in the chain of calls leading to the point of error _by name_.
It seems to me that there's something of a circularity here. Either in your logic if applied to language design in general, or as a self-perpetuating habit when applied to Python in particular. The assumption is that functions are in some sense rather "big" things -- that each function performs a well-defined action which can be understood in isolation. That may well be true in idiomatically written Python (I've never cared for the look of the language myself, so I don't know what's considered "normal"), but it isn't true in general. With the assumption, it makes sense to say that every function /could/ have a name, and so, why not /give/ it a name ? But without the assumption, when many little anonymous functions are used, the idea of giving them all names appears pettifogging to the point of idiocy. If the language and/or culture expects that all/most functions will be named, then "little" functions (in my sense) won't be used; hence the self-perpetuating habit. But I don't think that the underlying logic supports that habit independently of its own self-perpetuating nature. E.g. consider the Smalltalk code (assumed to be the body of a method): aCollection do: [:each | each > 0 ifTrue: [^ true]]. ^ false. which iterates over a collection checking to see if any element is > 0. If so then the method answers true ("^" -- spelled "return" in Java), otherwise it answers false. In that code, [^ true] is syntactically and semantically an anonymous function, which is only invoked if the antecedent is true (in point of fact the compiler inlines that function away but I don't think that's relevant here). The passage beginning [:each | ... and reaching to the matching ] is also an anonymous function with one parameter (each) which is applied to each element of the collection in turn. (In this case it really is an anonymous function, even at the implementation level.) What "name" would you give to either of them ? I don't believe that /any/ name is possible, and certainly that no name is desirable. In my working Smalltalk environment today, there are 60099 methods defined across 3369 classes. In that codebase there are 38112 anonymous functions. Do you really want to have to find names for them all ? -- chris -- http://mail.python.org/mailman/listinfo/python-list