B
25

My coworker told me to stop using brute force for loops in Python, I ignored him for 3 months

My senior dev kept saying 'just use list comprehension, trust me' and I kept thinking it was a waste of time to rewrite working code. Then last week I ran a script that took 45 seconds to process 10,000 records and he showed me how to cut it to 2 seconds with one line. Has anyone else dodged a basic optimization tip for way too long and then felt dumb when they finally tried it?
3 comments

Log in to join the discussion

Log In
3 Comments
anthony129
Oh man, 45 seconds to 2 seconds? That's a rough one. But I gotta push back a little on the 3 month thing. You didn't really dodge it for 3 months, you dodged it for like 30 minutes. Because after you first heard it, you could have just googled "list comprehension vs for loop speed" and seen the difference in 5 minutes. That's on you for not even checking before dismissing it. Like, I get that working code feels safe, but if your senior dev is literally telling you something and you just ignore it for a quarter of a year, that's a communication problem not a code problem. Glad you finally saw the light though, list comps are basically magic for that kind of stuff.
7
jamesf41
jamesf417d ago
...and then you see the same thing happen when people dig in their heels about learning to use a new tool, like a cordless crimper versus the old manual one. They know the new way is faster, they've seen the numbers, but they'll still spend a whole day fighting with the old setup because "that's how I've always done it." It's not about the code or the tool, it's about not wanting to admit you might have been doing it the hard way. Once you actually try it, you feel dumb for waiting so long.
5
susan649
susan6497d ago
We've all been there, and the real trick is just taking 10 minutes to test their theory yourself next time. Once you see that 45 seconds drop to 2, you'll never go back to writing loops like that again.
6