3 ms·
If you give something a name, yet still only use it once, what's the point? It is just semantic clutter to do that (unless, of course, you can't use multiline l
by rw 17y ago
If you give something a name, yet still only use it once, what's the point? It is just semantic clutter to do that (unless, of course, you can't use multiline lambdas...).
- CaptSolo 17y agoThere is no big harm in giving something a name. Giving a name also helps if you find a need to reuse it later. Plus a name can give a hint to what this code is for.
- rw 17y agoYet, if you look in functional programming code (e.g. Haskell, Scheme), you'll find many anonymous lambdas (that in python would be > 1 line). Why would good coders bother doing that?
- eru 17y agoIf something is small and enough to be anonymous, it's usually simply enough to be expressed without binding a variable. (See point-free style.)
- GeneralMaximus 17y agoIn Python, you can easily define methods within methods, so there is little semantic clutter at the toplevel. def doSomething(): def doSomethingElse(): # Code goes here. pass eggs = filter(doSomethingElse, spam) for cheese in eggs: # Do something. pass