3 ms·
> Why is it such a problem to move your closure to its own line and give it a name? That's actually one of my bigger beefs with Python: it forces a large namin
by __david__ 10y ago
> Why is it such a problem to move your closure to its own line and give it a name?
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.
- ctrlc-root 10y ago> 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.
- xapata 10y agoWhenever I have difficulty thinking of a good name for an intermediate step, I start to worry that my algorithm is unnecessarily complicated.
- dragonwriter 10y ago> Also, naming something implies it will be useful in another context, which one-off lambdas rarely are. 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.