3 ms·
I have only been writing python since Guido wrote that comment, but I have to say I don’t agree with him. I find the map/filter syntax to be very readable and i
by deepsquirrelnet 3y ago
I have only been writing python since Guido wrote that comment, but I have to say I don’t agree with him. I find the map/filter syntax to be very readable and intuitive. List comprehension is ok but to me becomes nearly incomprehensible (see what I did there?) where nesting is involved.
It’s easy to chain map and filter statements without losing readability. I think I might be in the minority though.
- leetrout 3y agoIt's a "when in Rome..." situation. Theres nothing wrong with using them but what you are going to find across the community are comprehensions. They concisely bring the data container and the iteration together with no fuss. If you need to map and reduce and filter and want to build a chain and/or have reusable predicate functions then go for it. I always encourage my teams to reach for the ecosystem usage before doing things because another language does it different (map/filter/reduce being the best option in JS 90% of the time). But maybe you work at a functional shop and everyone Gets It(tm) and then it is the norm.
- galangalalgol 3y agoThey both seem self evident, though I prefer the functional syntax. I don't write enough python that I don't have to look stuff up each time it comes up. C++ and Rust are my normal tools, and they are both fine having a couple ways to do something. Is the "one way to do something" matra still a guiding principle for Python? Having multiple ways means when I guess at syntax I have more chances to be right. There also seem to be really stong opinions about what is idiomatic. I find writing python without lots of typehints and a good IDE to be infuriating, but I've been told type hints aren't pythonic.
- deepsquirrelnet 3y agoTo me, the concept of “pythonic” has lost credibility for all the reasons you mention. It used to be that “duck typing” was a point of pride, something everybody learned. Now if you’re not type hinting, I think most people consider it bad practice. There’s a bajillion ways to do everything. We use print() now, but not raise(). f-strings or .format()? Maybe c-style string formatting? How about dict formatting? Is adding strings ever permissible? Didn’t we used to use single quotes? I thought that was pythonic too. Pythonic doesn’t exist. What’s popular is all there is. I say let’s bring map, filter and reduce into fashion.