🎙️
24

A senior dev told me my code was "too clever" and it stung at first

I was working on a Ruby on Rails app about 2 years ago, trying to chain a bunch of methods into one tight line. He pulled me aside and said, "If you have to leave a comment to explain it, it's not clever, it's confusing." I switched to writing longer, uglier functions that anyone could read in 2 seconds. Now I catch myself doing that same thing to junior devs and I get why he said it. Anyone else struggle with writing code that's "too smart" for its own good?
2 comments

Log in to join the discussion

Log In
2 Comments
garcia.tyler
Oh man, I definitely went through that phase too. There was this time I wrote a one-liner in Python that sorted a list, filtered some results, and mapped a transformation all in like 80 characters. Felt like a genius until my coworker asked me to walk through it during code review and I couldn't even follow my own logic without reading it three times. Now I break things into smaller steps with plain variable names like "filtered_list" or "sorted_results" so the next person (or future me) can just read it top to bottom without needing a decoder ring. That senior dev probably saved you from a lot of late night debugging sessions where you'd be staring at your own "clever" code wondering what you were thinking.
6
jade_johnson
Wait, is readability really the only thing that matters though? Sometimes "ugly" code can be just as confusing when you have like 15 lines of nested loops and temp variables that don't tell you the actual intent. I've seen that one-liner Python situation turn into a 50 line monster where you still have to trace through each step. Long boring code can hide bugs just as well as short clever code if nobody checks the logic.
4