this post was submitted on 06 Jan 2024
495 points (96.3% liked)

Programmer Humor

32050 readers
1418 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 8 points 8 months ago (1 children)

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.

[–] [email protected] 4 points 8 months ago* (last edited 8 months ago)

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.