7
Broke my entire dev environment because I named a variable "data" 47 times in one file
Spent 3 hours last Wednesday tracking down a bug that turned out to be me overwriting the same variable in a loop, and now I always prefix my globals with "g_" like a paranoid person - anyone else have a naming convention they swear by after one disaster?
3 comments
Log in to join the discussion
Log In3 Comments
jake98611d ago
dude i feel you on this so hard. spent like 4 hours one sunday trying to figure out why my shopping cart kept doubling items every time someone added something. turned out i had a variable called "cartTotal" that i was using both as a string for display and then later as a number for calculations. now i name everything based on what it actually holds like "cartTotalString" or "cartTotalNumber". sounds dumb but it saved me twice already. the const thing you mentioned is legit too, i started doing that after that same bug and it honestly helps more than any naming thing.
10
kaih3610d ago
Oh man, I've been there too, naming stuff after its actual type is such a simple but huge lifesaver.
7
uma_ellis11d ago
47 times in one file, that's rough honestly. But I actually disagree with g_ prefixes as a rule. I tried that after my own variable disaster and it just made my code harder to read. All those underscores everywhere felt like clutter. Now I just use really specific names like `userData` or `tempData` or `loopCounter` instead of `data`. It takes a few extra seconds but saves me hours later. I also started using const by default unless I really need to reassign something. That alone stops most of my accidental overwrites. The g_ thing always feels like a bandaid to me when the real fix is just picking clearer names from the start.
8