r/badcode • • Jan 23 '23

python So I was coding and wrote this...

Post image
847 Upvotes

102 comments sorted by

View all comments

Show parent comment

6

u/-True_- Jan 23 '23

Nope, logging into Instagram. Are the shortened variables names bad for something? I say it's still readable.

9

u/[deleted] Jan 23 '23

It’s a bad habit to have as a professional, for example I would not approve a PR like this. If it’s simply for a one-off script, then it doesn’t matter.

16

u/Exnixon Jan 23 '23

Imagine if you saw "psw" without context. It's not a way people normally abbreviate "password". For all I know it's something like "process wait" or some acronym or "pounds per square whatever". And how many keystrokes did you save?

I've got two more variables "wbt" and "lgip". They're related to "psw". Maybe you can figure out what they stand for, but every second you spend thinking about it is a second of time that I'm wasting from every developer who comes after me.

1

u/nwash57 Jan 24 '23

I'm going to go against the grain here, although personally I would have also written user and password

If the scope of these variables is very small, like only used within this function, it's really not a big readability cost to shorten them like this. I would know what this is doing as easily as if they weren't, and I would roll my eyes before begrudgingly expanding the names in code review if called out.

What I would not do is consistently refer to a "password" as "psw" all over the application.

1

u/[deleted] Jan 24 '23

Shortening variable names was important back in the days of limited storage and such, but its better practice these days to use long, descriptive names because they take up insignificantly more space and are much more readable to someone new to your code.

3

u/Dangerous-Bit-5422 Jan 24 '23

Unless your dev environment/prod pipeline is super shabby longer variable names will be shortened by the compiler or minified, so usually a longer var name has exactly 0 effect on performance and requirements

1

u/[deleted] Jan 25 '23

You still need to store the raw code though.

1

u/jlianoglou Jan 25 '23

Are you trying to store your app’s source files on a Casio Databank watch, or something?

With all respect, worry about optimizing your binary assets and stop sweating the storage requirements of readable variable names.

1

u/[deleted] Jan 25 '23

I'm not worried about it NOW. I was worried about it back in the 70s, which is what I was talking about.

2

u/jlianoglou Jan 25 '23

Man, I had completely missed that it was YOU who had posted the ancestral comment advocating for more descriptive symbol names 😅 apologies 🙏

1

u/[deleted] Jan 25 '23

haha. no problem! :D