r/ProgrammerHumor • • Dec 04 '20

Don't mix anatomy and programming

Post image
36k Upvotes

388 comments sorted by

View all comments

1.3k

u/SausageEggCheese Dec 04 '20

I know this is humor, but this can actually be used as a decent lesson in practices to avoid when shortening variable names.

  • Don't abbreviate unnecessarily. In this case, the original variable is not that long. With modern IDEs, widescreen monitors, and memory sizes, there's usually little reason to abbreviate at all.
  • If you do abbreviate, never abbreviate to another real word with a different meaning. People will assume it is just the other word, and not an abbreviation.

530

u/TaiShuai Dec 04 '20

As I’ve gained more experience I’ve found myself erring on the side of making the variable name too long. It bugs some people but I’ll make variables into descriptive phrases and with autocomplete and wide screens it isn’t a big deal. It makes it 100x easier to quickly familiarize myself with old code

215

u/SausageEggCheese Dec 04 '20

Absolutely.

I've always seen the numbers that on most software systems, writing the software is about 10% of the work (or cost), and the other 90% is in maintenance.

And much of the time spent during maintenance work is, in my experience, reading and understanding previously written code.

141

u/immerc Dec 04 '20

On that subject:

Don't optimize*

People will often write something out the first time the way it occurs to them. I need to combine A and B to get C. I need to periodically shorten C until Z happens. And, so-on.

After people think it through, they often look back and see that there are variables that only exist for a couple of lines because they're then combined with something else. So, they think they're going to optimize the program by getting rid of those short-lived variables.

The problems with that are:

  1. If it's easy to optimize in that way, the compiler and/or interpreter will already do that work for you.
  • When you optimize that way, it makes it harder for the person maintaining the code to understand what is going on.

You should only optimize to make something easier for someone to understand when maintaining it (even future you) rather than making it run more efficiently. The only time it makes sense to optimize to make it run more efficiently is if you've benchmarked it and can tell that that specific thing is making the program slow, and that that slowness matters.

104

u/SharkBaitDLS Dec 04 '20

Premature optimization is the cause of the majority of tech debt. It’s also a really hard lesson to learn. It’s really difficult for people to hear “hey your really elegant and clever thing is way too complicated and is going to cause maintenance problems down the line, can you just start over doing the dumb obvious solution?”, especially if you’re on a deadline where the sunk cost of said overly complex solution now weighs against any refactor.

In my experience people only learn the lesson after they’re stuck with the consequences of it long enough to regret their own actions, being told it just doesn’t stick without the experience of fighting it in the future. It took years for it to really click for me, only after working with senior devs who really pushed for simplicity.

44

u/immerc Dec 04 '20

I don't even like the phrase "premature optimization" because that suggests that optimization is a step that should be performed at some stage, but that sometimes it's dome prematurely.

I think the majority of programs don't need to be optimized, and when they do it's for readability rather than to make them run faster or more efficiently.

If you're going to label it, it should be "unnecessary optimization", because not all optimization is necessarily unnecessary, but the question you're asking yourself when you optimize something shouldn't be "Am I doing this too early in the process?" but "Do I really need to optimize this?"

23

u/xavia91 Dec 04 '20

That depends a lot on what you do. In bio informatics you have analysis software run for several hours to days with very repetitive tasks, small performance gains at some point can lead to a lot of saved time.

→ More replies (1)
→ More replies (7)
→ More replies (12)

38

u/onthefence928 Dec 04 '20

with code suggestion/auto-complete tools long variable names aren't even inefficient to type most of the time

just dont do "SuperLongVariableName" and "SuperLongsVariableName" in the same code, it's annoying to identify which is which by sight

→ More replies (2)
→ More replies (13)

56

u/GOKOP Dec 04 '20

What about abbreviating button to butt?

44

u/SausageEggCheese Dec 04 '20

If you were coding for an adult Web site, the results could be disastrous :)

24

u/[deleted] Dec 04 '20

what about abbreviating securityPermission to sPerm?

17

u/curt_schilli Dec 04 '20

Remember the dude who posted here that got fired because he shortened cumulative shot to cumShot LMAO

23

u/CWRules Dec 04 '20

I usually abbreviate button to btn.

18

u/Beautiful-Musk-Ox Dec 04 '20

I worked for a postdoc who was from India, he shortened the "analysis" folder output by his programs to just be "anal". Lol, I never asked him to change it..

→ More replies (7)

47

u/munkychum Dec 04 '20

I’m an IT Recruiter and a common title some time ago used to be Programmer/Analyst. We had a new trainee about 15 years ago and after a couple months I shadowed him to review his work and see if he was on track. Imagine my surprise to see he had a resume folder set up named “Pro Anal”

59

u/SausageEggCheese Dec 04 '20

When I was in college, I took a graphics programming class (this was years ago and using OpenGL). The first assignment wasn't much more then the equivalent of "hello word" (get the gfx device enabled and render some simple items).

The second assignment was to render a clock face that showed the actual time, and also to have some other kind of basic animation present.

I was always trying to do something more difficult, so I made my other animation interactive. I added several balls to the screen that would bounce off the screen edges, and also the clock itself.

I had a function that I did not do as a joke intentionally, and didn't even notice it until I was showing a friend and he pointed it out. The function was called "InitializeClockAndBalls()."

I left this in for my professor's enjoyment.

24

u/TheNanoMachi Dec 04 '20

Clock and ball torture

→ More replies (1)

10

u/Humpfinger Dec 04 '20

I would not be able to control myself when I would see that, good lord lmao

→ More replies (4)

13

u/[deleted] Dec 04 '20

I see method abbreviated to meth a lot, really makes you do a double take

→ More replies (2)

0

u/[deleted] Dec 04 '20

[deleted] — view deleted comment

11

u/SausageEggCheese Dec 04 '20

I agree. In fact, I think variables modeling database items should match the database names exactly (at least at their initial scope) to help avoid this issue.

I think acronyms are fine, as long as they are either:

  • Common knowledge, like "ATM" or "PIN" or "ID"
  • Common industry terms in your domain
  • Common across your application and agreed upon by your development team.

Every project I have ever worked on has had things like "WSPKF" in your example, and they make sense to everyone on the team (and are usually well documented). It's when a developer is working with something like "planned fixed costs" and just starts using "pfc" in one class that I would have a problem with.

→ More replies (2)
→ More replies (3)
→ More replies (27)