F
10

My friend said my code looked like alphabet soup and I finally get why

I was showing him a Python script I wrote to sort my movie list. He stared at it for a minute and said, 'Dude, your variable names are just letters. What does 'x' even hold?' I had things like 'a', 'b', and 'c' everywhere. The next day, I went back and changed them all to real names like 'movie_title' and 'release_year'. Suddenly, I could actually read my own work a week later. Has anyone else had to fix a habit like that?
4 comments

Log in to join the discussion

Log In
4 Comments
wade_dixon
wade_dixon1mo ago
Time travel tax" is such a perfect way to describe that pain lol.
8
charlesschmidt
I mean, I get why people say that but honestly I think short variable names can be fine if you're just messing around with a quick script for yourself. Like if I'm writing something to sort my downloads folder real quick, I'll use 'f' for file and 'p' for path and it's not a big deal because I'm never gonna look at it again. The problem is when people treat every single script like it's gonna be a production app that someone else needs to read. Not everything needs a full variable name like 'temporary_file_path_for_renaming_process_part_two'. Sometimes 'x' is just a counter and everyone knows that. I've been reading and writing code for years and I can tell what 'i', 'j', and 'k' are doing in a loop without needing them spelled out. Maybe it's just me but I think the real skill is knowing when you need long names and when a single letter is perfectly fine.
5
rivera.hannah
Yeah, the part about reading your own work a week later really hits home. I read a blog post once that called bad variable names "time travel tax" because you pay for it later when you're confused. It's so true, changing a few letters to real words saves so much headache. I still catch myself using 'temp' for everything and have to go back and fix it.
1
rosepark
rosepark1mo ago
What's the worst "time travel tax" you've paid, @wade_dixon?
3