by __david__ · 9y ago · 0 comments
That's actually one of my bigger beefs with Python: it forces a large naming burden on the programmer. When writing python code I find myself struggling to name intermediate results or stupid functions that should just be lambdas. Very very often those results don't warrant a name, or are unnameable. Also, naming something implies it will be useful in another context, which one-off lambdas rarely are.
Not necessarily. I find it helps readability to do this:
def prunde_indices(indices, cutoff):
def match_old_index(index):
return index.timestamp < cutoff
old_indices = filter(match_old_index, indices)
# ... do things with old_indices
as opposed to using an anonymous lambda. That doesn't mean I have to reuse it outside of this function.Naming something in a local scope doesn't imply that it will be useful other than at least one place on that local scope. In fact, it's a pretty clear indication that you don't expect to need it anywhere outside of that scope.