H
21

A senior dev told me my variable names were like alphabet soup

I was showing him my first Python script, a simple budget tracker. He looked at it for a minute and said, 'I have no idea what x, y, and z mean here.' I was using single letters for everything. He told me to use names that describe the data, like 'monthly_income' and 'total_expenses'. I changed all my variable names that night and my code is so much easier to read now. What's the best tip you got for writing cleaner code as a beginner?
2 comments

Log in to join the discussion

Log In
2 Comments
carr.willow
Single letters for everything" is why my old code felt like a foreign language.
7
margaret_bennett3
Oh man, I read this article about how single-letter variables are a huge pain for anyone trying to read the code later, even the person who wrote it! It totally made me think of what @carr.willow said about old code feeling like a foreign language. The writer called it "selfish coding" because you save a few seconds typing but waste hours later trying to remember what "x" or "k" was supposed to mean. It's so much clearer to just write out what the thing actually is, like "userCount" instead of just "c". That tiny bit of extra typing saves so much headache.
5