0

I have read that using anonymous functions can improve readability in Python. Anytime I come across one I find that they slow me down because I have to think about it instead of simply reading a good function name. I know that Python supports many paradigms and this just allows access to a more functional way of programming. It seems to me that they should be avoided since readability is such an important tenant in Python. So the question is how do I use anonymous functions in a way that doesn't hamper readability to a person new to my code?

This was a good post, but it didn't answer the question I am asking.

What are the benefits to using anonymous functions instead of named functions for callbacks and parameters in JavaScript event code?

chadmc
  • 81
  • 1
  • 7
  • 2
    This question is too opinion-based, I think. In general, `lambda` expressions are good as one-off arguments to higher-order functions. Any time they get too complicated, you can simply use a full function definition statement. There really is no necessity for `lambda` expressions. – juanpa.arrivillaga Mar 16 '20 at 04:20
  • Besides, Python is not JavaScript (which is what the linked question talks about). JavaScript syntax is very conducive to anonymous function use, especially with the new arrow syntax. In Python, anonymous functions are super restricted, and often considered ugly, if they are any complex than e.g. `lambda x: x['foo'].upper()`. – Amadan Mar 16 '20 at 04:23
  • 2
    This is like `regex`.It is happy and fast to use,but hard to read it. – jizhihaoSAMA Mar 16 '20 at 04:24
  • 1
    Related: [Why are Python lambdas useful?](https://stackoverflow.com/q/890128/4518341) – wjandrea Mar 16 '20 at 18:47

0 Answers0