4 ms·
I feel like under score just makes your code compact. They're also ignoring that I might want to be doing input validation while iterating over those lists. Fo
by ASneakyFox 12y ago
I feel like under score just makes your code compact. They're also ignoring that I might want to be doing input validation while iterating over those lists. Forcing me to add a loop right after that very compact code and nullifying it only purpose. Then on top of that ill need to add comments to explain the compact and cryptic code.
I really don't see the benefit.
- gravity13 12y ago| I really don't see the benefit. And you won't while you just pass it off as something that "just makes your code compact." Regarding your comment about comments -> imagine a world where there were no for loops, then somebody invents a for loop. What would you say to the person who shoots it down because it just "makes code compact" and programmers don't want to have to add a comment above a cryptic 'for loop' explaining what it does?
- Zak 12y agoYou don't have to add a loop to do your validation: if not all(is_valid, the_values): inform_user("You supplied bad data") Or perhaps bad_values = select(is_not_valid, the_values) if some(bad_values): inform_user("The following values were bad", bad_values) Yes, sometimes you might want to do several things in a single iteration for reasons of efficiency, but in that case you can compose() the functions representing the per-element operations. This code is only "cryptic" to people not used to functional programming. If the intended audience is the set of everyone who knows Python, using these abstractions will reduce the number of people who understand the code. If it's your startup's team of three programmers, there's a good chance the time saved is worth the learning curve.