11
Wish someone told me about variable naming earlier
I spent 3 hours last night debugging a script because I named a variable 'data' and then reused the same name in a loop. It just overwrote everything and I couldn't figure out why my output was blank. My buddy showed me how a simple rename to 'file_data' fixed the whole thing. Has anyone else wasted a day on stupid naming mistakes like this?
3 comments
Log in to join the discussion
Log In3 Comments
hart.mark28d ago
Man I read somewhere that programmers spend like 35% of their time just reading and understanding variable names. That number made me realize how much bad naming actually costs us. Ever try going back to code you wrote six months ago and having no clue what 'x' or 'temp' was supposed to do?
8
perez.patricia28d ago
Yeah I read a study a while back that said something similar @hart.mark, like developers spend almost half their time just figuring out what the code is supposed to do instead of actually changing it. The worst is when someone uses "data" as a variable name for a completely different thing in every function, drives me insane. I swear I've wasted whole afternoons hunting down what "temp" meant in some old script from 2018. Simple stuff like "userAge" instead of "ua" saves everyone's sanity.
5
terry_thomas19d agoMost Upvoted
Ugh tell me about it @hart.mark. I spent three hours last week tracking down a bug because someone named a variable "tmp" in one function and "tmp2" in another for completely different things. And of course the second one was overwriting the first with no warning. @perez.patricia you're spot on about "data" too, I've seen that in like five different contexts in the same file. Makes you wonder how much money companies pour into just decoding bad names.
3