19
Got a code review that stung at first but totally changed how I name variables
About 3 months ago a senior dev on a project I was helping with told me my variable names were 'too clever'. I had stuff like 'theData' and 'tempResult' thinking it was fine for a beginner script. He explained that in a 500 line file, someone reading it shouldn't have to guess what 'temp' means. I changed to stuff like 'customerPhoneList' and 'finalTaxAmount' instead. Now I even add little comments on tricky loops, which I never did before. Has a specific piece of feedback ever made you totally rethink your code approach?
4 comments
Log in to join the discussion
Log In4 Comments
pat_roberts5516d ago
Oh man, your comment about 'tempResult' hit home. I used to do the exact same thing and a guy on my team roasted me for it. Now I write variable names that actually describe what they are and it makes debugging way less painful.
6
young.ryan16d ago
Nodding so hard reading this, @pat_roberts55. I had this one project where I named a variable 'data' and then a second one 'data2' (like that's any better) and spent three hours tracing a bug that was just me confusing the two. My teammate finally tagged me in a code review with a screenshot of my variable names and just wrote 'why' in all caps. Now I force myself to name things like 'customerEmailList' or 'filteredPurchaseHistory' and honestly it's boring but it saves me from those late night facepalm sessions.
6
grant15516d ago
My 'data2' was actually named 'data_really' somehow lol.
4
Oh man, the 'data2' thing hits way too close to home. I once had a script where I had 'listCustomers' and then 'listCustomers2' because I needed to filter it and couldn't be bothered to think of a real name. Spent an hour trying to figure out why the second list wasn't updating before I realized I was reading from the wrong variable the whole time. That 'why' comment from your teammate is brutal but honestly the kind of wakeup call we all need sometimes. Now I just sit there for an extra 30 seconds to type 'filteredActiveCustomers' and it saves me so much headache later.
5