I was mildly annoyed the other day when someone moved a works-fine function and reimplemented it with dropwhile. This apparently was a divisive idea.
Me: it worked fine. Don’t reimplement it for no gains. Don’t send people to somewhat esoteric parts of the standard library. No one on this team is going to know how that function works off the top of their head.
Them: it’s in the standard library it’s fair game. It still works.
One benefit of using dropwhile is that (with a bit of practice) it can actually be easier to read than a for loop. All for loops look similar. You need to read the for loop line by line to understand what it really do.
With dropwhile (or map, filter and reduce), it’s immediately obvious it will drop all elements until a certain condition turns false.
Skip. As in, “drop the first 5 elements of this iterable.” dropwhile is “drop each element until the given predicate is satisfied.” It’s really not that obscure, I dunno what the original commenter is on about
I was mildly annoyed the other day when someone moved a works-fine function and reimplemented it with dropwhile. This apparently was a divisive idea.
Me: it worked fine. Don’t reimplement it for no gains. Don’t send people to somewhat esoteric parts of the standard library. No one on this team is going to know how that function works off the top of their head.
Them: it’s in the standard library it’s fair game. It still works.
One benefit of using dropwhile is that (with a bit of practice) it can actually be easier to read than a for loop. All for loops look similar. You need to read the for loop line by line to understand what it really do.
With dropwhile (or map, filter and reduce), it’s immediately obvious it will drop all elements until a certain condition turns false.
What the hell is a drop
Skip. As in, “drop the first 5 elements of this iterable.” dropwhile is “drop each element until the given predicate is satisfied.” It’s really not that obscure, I dunno what the original commenter is on about
Yeah, I’m not even a python dev, I knew what dropwhile did immediately from the name. Some people just don’t want to learn anything new, ever.