V
2

Learned the hard way why you shouldn't name your variables 'data'

I was working on a little Python project for my portfolio, and every single function I wrote had a variable called 'data'. List of user info? data. Dictionary of scores? data. String from an API call? you guessed it, data. Then I tried to debug a loop after 3 days away from the code and I couldn't tell what anything was doing. I spent 2 hours just tracing which 'data' was which. That's when it clicked for me. Now I name things like 'user_scores' or 'api_response' and my code makes sense the next morning. Does anyone else have a bad naming habit they had to break?
3 comments

Log in to join the discussion

Log In
3 Comments
young.michael
Takes practice naming things clearly everywhere, not just code. Harder than it sounds?
8
fiona_kim97
I once named a variable "stuff" and spent an hour wondering why it was empty.
7
abby_morgan18
I read somewhere that programmers actually spend way more time READING code than writing it, so clear names save SO much future headache. It's like how having a messy room makes it impossible to find your keys, except the keys are bugs and the room is a 5000 line file. Really makes you appreciate the people who take those extra 5 seconds to name things properly.
3