3 ms·
Sure, but those are one-line functions, which Python supports through lambdas. (Incidentally, some of them could be done with the operator module, without defin
by andreasvc 12y ago
Sure, but those are one-line functions, which Python supports through lambdas. (Incidentally, some of them could be done with the operator module, without defining a new function). I would argue that once you write a multi-line function, it makes sense to give it a name and define it separately, which makes the "no multi-line anonymous functions" complaint less pressing.
- BugBrother 12y agoLet me give you an example from my experience. I wrote an elegant parser definition library, used for parsing specialized output of ... never mind. It had hierarchic specifications (regular expressions etc) of parsing states, along with anonymous functions which stored away parsed data and sent the parser among different states. New juniors could after a few hours use this to quickly parse complex text documents. I cursed a lot while trying to port this to Python. :-( A dozen named sub-ten lines functions specified by names and referenced inside a parser structure? Just didn't work. Edit: The point is, there are use cases where real lambdas are useful (except from map etc). It is just weird to argue otherwise.
- jsmeaton 12y agoI'm a python guy and I totally agree that multiline anonymous functions greatly enhance the readability of code in certain applications. You can do everything with named functions, but it's not always the best method for conveying meaning. I can live without multiline anonymous functions - but I'd make use of them if they did exist.