T
15

PSA: Stop naming your variables x, y, and temp in every script

I help moderate a small coding group for absolute beginners, and I keep seeing the same mistake over and over. People write a 50-line script with variables named x, y, temp, data1, data2, and it drives me crazy because you can't tell what anything does after two days. I did this myself when I first started learning Python six months ago, and I spent three hours debugging a simple loop because I forgot which 'temp' held the user input and which held the calculation result. It matters because good names like 'user_age' or 'total_price' make your code almost self-documenting, and you'll thank yourself when you come back to fix a bug next week. Seriously, just take the extra 10 seconds to type a real word instead of 'a' or 'val'. Has anyone else run into a situation where bad variable names caused a real headache?
2 comments

Log in to join the discussion

Log In
2 Comments
hugoj86
hugoj8622d ago
Fair point but sometimes x and y are fine for quick throwaway scripts.
5
jade_grant95
jade_grant9522d agoMost Upvoted
Hugoj86, your point about x and y being fine for quick scripts makes sense, but nobody talks about how bad variable names like that hurt readability when you come back to them a week later. I've lost way too much time trying to figure out what 'x' was supposed to hold in a script I thought was throwaway. The time you save typing x and y gets eaten up when you have to debug or reuse it.
9