4 ms·
This is just a bad example. I would use a closure here for the simple fact that it's simpler. No need to create an extra class with __call__ magic when you can
by j_baker 12y ago
This is just a bad example. I would use a closure here for the simple fact that it's simpler. No need to create an extra class with __call__ magic when you can just return a closure.
Now, if you're doing something more complex, a class complete with self parameters is simply unavoidable.
- twic 12y agoIt is a bad example. Or at least a contrived one. A class with one member, that member being __call__, would be an odd thing to write. Showing how to convert a class which should have been a function all along into a function is not hugely helpful.