11 ms·
Sometimes a lambda is more readable. "lambda x : x if x else 1" is pretty understandable and doesn't need to be it's own separately defined function. I should
by throwaway889900 1y ago
Sometimes a lambda is more readable. "lambda x : x if x else 1" is pretty understandable and doesn't need to be it's own separately defined function.
I should also note that development style also depends on tools, so if your IDE makes inline functions more readable in it's display, it's fine to use concisely defined lambdas.
Readablity is a personal preference thing at some point after all.
- gopher_space 1y agoMy cleverest one-liners will block me when I come back to them unless I write a few paragraphs of explanation as well.
- ethbr1 1y ago>> Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -- Brian Kernighan https://github.com/dwmkerr/hacker-laws#kernighans-law https://github.com/dwmkerr/hacker-laws#kernighans-law
- johnnyanmac 1y agoYmmv. Know your language and how it treats such functions on the low level. It's probably fine for Javascript, it might be a disaster in C++ (indirectly).
- deleted 1y ago[deleted]
- banannaise 1y ago> "lambda x : x if x else 1" I think what you're looking for is "x or 1"