| Usually list comprehensions are a much cleaner way to write a map. This I love. Personally what I love most about using more functional code aren't the clever lambda's and stuff, I actually try to avoid that because it looks weird in Python. What's really awesome is enclosing named functions inside bigger functions and using closures. The result is code where: 1. nobody can, by accident or intentionally, use inner functions of your algorithm, 2. self-documented code (function name says what the code block does) 3. you aren't passing a gazillion parameters around 4. or making everything messy with a bunch of unneeded OOP code. [I don't like useless OOP code. Objects-just-for-the-sake-of-encapsulation are silly.] edited for wall-of-text |
But the first makes my intent clearer than the second:
In Python, where creating anonymous functions is syntactically expensive, list-comprehension syntax may be cheaper in many cases, but it's not clearer. When I want to map or filter something, I want to _say_ that I'm mapping or filtering, not explain to Python how to map or filter that thing in terms of list-comprehension syntax. Nor do I want to burden the reader with interpreting that syntax to figure out that it's a mapping or filtering operation.I want my code to say what I mean, not just evaluate to what I mean.