T
15
c/coding-for-beginnerscaseyriveracaseyrivera15d agoMost Upvoted

Just read that 70 percent of bugs come from variable naming issues

I was skimming a study from a coding blog called Dev Trends. It said bad variable names cause way more bugs than logic errors. That surprised me because I always thought the hard part was the algorithms. Now I double check my variable names before I even write a function. Has anyone else had a bug that traced back to a weirdly named variable?
2 comments

Log in to join the discussion

Log In
2 Comments
oliver_torres4
Actually, I've been bitten by exactly this more times than I care to count. There was this one time I had a variable called "temp" that was supposed to hold a user's temporary session token. But then later in the same function, I used "temp" again for a loop counter. It took me three hours to find the bug because the code compiled fine but the session kept expiring randomly. That's not just annoying to read, it actually broke the whole feature. Now I force myself to use names like "sessionToken" and "loopIndex" even if they're longer. The extra typing is way less painful than tracking down a ghost bug later.
6
the_wren
the_wren15d ago
Big disagree on this one. Bad variable names can slow you down but logic errors are way more likely to crash your whole program. A weirdly named variable is usually just annoying to read, not the actual cause of a failure.
2