B
21

My coworker told me my code was 'too clever' and I finally got it

She said readability matters more than showing off with one-liners, and she was right. I went back to a project from 3 months ago and couldn't even follow my own logic. Has anyone else had to unlearn bad habits from trying to look smart?
3 comments

Log in to join the discussion

Log In
3 Comments
patricialee
Same thing with overstuffing a suitcase... you regret it later.
4
the_viola
the_viola12d ago
Three years ago I had a function that was literally one line with three ternary operators nested inside each other and I was so proud of myself for being clever. Then I had to debug it at 2am during a production issue and wanted to punch past me in the face. My coworker finally sat me down and showed me his code that was like 20 lines long but anyone could read it in two seconds. Now I write for the person who has to maintain it six months from now, not for the person trying to impress someone on a code review.
0
ellis.leo
ellis.leo11d ago
See, I actually disagree here. That one-liner ternary mess might have been hard to read but it was also probably way less code to trip over later. I've seen code bases where people spread everything out to be "readable" and then you end up with 2000 line files that are a nightmare to scroll through anyway. Sometimes compressing logic forces you to think about the actual flow instead of padding it with unnecessary variables and comments. And honestly, if you're debugging at 2am and can't trace a simple ternary chain, the problem might be more about not knowing your own code well enough.
1