T
22

TIL a simple trick to make your code way easier to read

I was watching a coding tutorial on YouTube yesterday and the guy kept saying 'name your variables what they are'. He showed his old code where he had stuff like 'x' and 'temp' and then rewrote it with names like 'user_input' and 'is_valid'. It sounds so obvious now, but I was still using single letters for everything. My own project from last night is suddenly a mess to look at. What's one small change that made your code cleaner when you were starting?
2 comments

Log in to join the discussion

Log In
2 Comments
luna_ramirez
My old loops were full of "i" and "j" too.
7
elizabethhart
Oh man, that's the real one. I learned to write comments that explain why the code is there, not just what it does. My old comments were useless, like "add one to counter." Now I try to say why we're counting at all. It forces you to think about the purpose and it saves future you so much headache.
7