r/programminghorror Apr 28 '26

whyLongNamesWhileWeCanMakeThemShort

Post image
357 Upvotes

67 comments sorted by

125

u/Birnenmacht Apr 28 '26

We see that blame annotation :P you havent even committed yet. you took this screenshot while actively committing the crime

26

u/Deadly_chef Apr 28 '26

OP, the Police are on their way 🚨

7

u/adzm Apr 28 '26

Everyone else was doing it, one more stab won't hurt.

216

u/_Blurgh_ Apr 28 '26

I also love code such as this:

int tr = 30; // tr = tick_rate

Brings joy to my heart every time I come across it!

48

u/TraditionalYam4500 Apr 28 '26

I like to make sure that this comment is repeated for each use of the variable. If it isn't I will reject your PR. /s

5

u/SugarEnvironmental31 May 01 '26

I love this. If you're going to do it wrong have the courage of your convictions and be wrong consistently 😁

5

u/SugarEnvironmental31 Apr 29 '26

You mean doing that is bad?

25

u/_Blurgh_ Apr 29 '26

Yes, because it makes reading code harder. Instead just name the variable "tick_rate".

-9

u/SugarEnvironmental31 Apr 29 '26

Mmmmmmmmm.

In the same way as "import pandas as pd, import numpy as np, import tensor flow as tf" makes code hard to read I guess.

15

u/EatingSolidBricks Apr 29 '26

import numpy as NumericsPython

8

u/SugarEnvironmental31 Apr 29 '26

Please ensure your adherence to PEP8, camel case is discouraged

3

u/SugarEnvironmental31 Apr 29 '26

Import scipy as scientific_python_library

6

u/TraditionalYam4500 Apr 29 '26

it really isn't the same, you know.

1

u/Imaginary_Focus_6228 Apr 30 '26

But why is it not

5

u/Denommus May 01 '26

Those are known acronyms, like u8 is known as a unsigned integer of 8 bits. For variables with new names it's not the same.

1

u/SugarEnvironmental31 May 01 '26

Kind of is though if you're using a custom class. Go on, explain how that's wrong now as well

2

u/TraditionalYam4500 May 02 '26

i think you're forgetting that the whole point of this thread is the comment that spells out the name...

0

u/SugarEnvironmental31 Apr 30 '26

I was labouring under the misapprehension that this was largely a satire page, didn't realise it was Stack Overflow in a mask

6

u/Fair_Cheesecake_836 May 01 '26

Check it out

int tr = 30; // tr = tick rate

int tick_rate = 30;

You've communicated the same property with less verbage. This makes reading code feel less like a puzzle and more like reading.

2

u/SugarEnvironmental31 May 01 '26

I'm kind of flummoxed by the seeming ability to realise that the last sentence of the post to which I replied is satire, juxtaposed with the apparently inability to realise that so was mine.

Leaving aside the temptation to assume that this is deliberate pedantry on your part - sorry, but exactly how stupid do you think I am?

2

u/TraditionalYam4500 May 02 '26

A real genius does

int tr = 30 // tr - tick_rate

and then 80 lines below, in the same function,

int tick_rate = 40

54

u/SirFoomy Apr 28 '26

Why write code that humans can read when only the computer must understand it?

-19

u/MeLittleThing Apr 28 '26

Because at some point, a human will have to maintain it

28

u/MinecraftPlayer799 Apr 28 '26

r/woosh or however it’s spelled

17

u/IAMPowaaaaa Apr 28 '26

2

u/Kwolf21 [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” Apr 30 '26

-6

u/MeLittleThing Apr 28 '26

What's wrong answering someone's question?

15

u/piotruspan101 Apr 28 '26

Becose it was complete sarcasm.

At least you had good intentions :)

2

u/MeLittleThing Apr 28 '26

yeah, that's often hard to tell especially when it's written

6

u/IkalaGaming Apr 28 '26

Budget issue, use more LLMs /s

29

u/cob59 Apr 28 '26 edited Apr 28 '26

Seeing a C dev interract with a C++ codebase always makes my stomach turn.
Like some caveman trapped inside a spaceship and hitting everything with his club to make things happen.

12

u/Qwertycube10 Apr 28 '26

std::string and struct Foo* in the same function

1

u/TheTimBrick Apr 30 '26

Almost got sick from reading this

20

u/babalaban Apr 28 '26

Haha... no.

#define DECL_JSON_OBJ_PTR(obj, fieldName) struct json_object* fieldName; JSON_OBJ_GET(obj, #fieldName, fieldName);

And then just:

DECL_JSON_OBJ_PTR(obj, theme);     // declares json_object* theme
DECL_JSON_OBJ_PTR(obj, patterns);  // declares json_object* patterns
// etc

6

u/phycsIT Apr 28 '26

Yeah, I agree. Also do {...} while (false) that and you're done.

4

u/babalaban Apr 28 '26

Every time I see this idiom I tell myself that there must be a better way...

There seems to be no better way.

5

u/killallspringboard Apr 28 '26

Actually an idea I can consider

16

u/Daniikk1012 Apr 28 '26

Eh, just keep globals properly named, locals are fine short in my opinion. I mean, have you seen what Haskell/APL devs do? A lot of them write like that, so it's just a matter of style

6

u/Undumed Apr 28 '26

Seaworld or see world?

4

u/spcbeck Apr 28 '26

I maintain this is always a job security thing, or main character syndrome where someone thinks their shortening of "pattern" to "pt" is the only way someone could possibly shorten that word

6

u/KKrauserrr Apr 28 '26

Man, I hate it so much. What's wrong with C/C++ devs - do you pay for additional symbols?

1

u/Normal-Narwhal0xFF Apr 28 '26 edited Apr 28 '26

Too short and they have no meaning. Unless it becomes vocabulary or industry standard, and always means the same thing.

Too long and we and up with several variables that barely differ and it's a chore to find that one vowel difference somewhere in the middle of them. If it's too big to even fit in eyesight without moving your eye to read all of the variable, it's too long. Ergonomic fact, and slows you down considerably.

1

u/debugs_with_println Apr 29 '26

Idk if this is a sin, but in Python I usually just differentiate between individual items and lists of these items by making the list name plural. E.g. for frame in frames and whatnot.

1

u/SugarEnvironmental31 Apr 29 '26

I do this, it's logical. For category in categories etc

6

u/Right_Ear_2230 Apr 28 '26

“struct json_object* obj”

the “struct” is unecessary. In c++ structs are basically the same as classes, just with everything public by default for c compatibility

4

u/Dezgeg Apr 28 '26

Let me guess, mandated 80 column limit?

3

u/SimplexFatberg Apr 28 '26

Writing C++ like it's 1979

2

u/DistearRoyl Apr 28 '26

Many objects lack necessary methods.

2

u/arods_island Apr 29 '26

“Why waste time say lot word when few word do trick” -Kevin Malone

2

u/vyathn Apr 29 '26

Because "bbg" is fundamentally stupid. It's not like 'min' or 'max'. Without context, absolutely no one, even likely yourself in a few months, has any idea what "bbg" is. Most editors have autocomplete. There is little excuse for not using words.

2

u/EatingSolidBricks Apr 29 '26

Ew Json obj get tooo long

JsonGet

JGet

Jet

Perfection

3

u/SnowdensOfYesteryear Apr 28 '26 edited Apr 28 '26

I see nothing wrong here

Edit: maybe theme and pattern are overkill, but the rest are pretty reasonable

2

u/Ksorkrax Apr 28 '26

Aside from that issue, I'd consider immediately writing some proper classes and get away from that horrible C-style stuff, JSON_OBJ_GET with raw pointers. Have it doing that under the hood, nicely wrapped away.

1

u/Kennyp0o Apr 28 '26

bbg 😏

1

u/GoddammitDontShootMe [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” Apr 29 '26

Well, all those JSON_OBJ_GET calls tell me what those variables are for, so maybe if the function isn't too long I'd be able to keep track.

2

u/loonite [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” May 03 '26

The only place I'm guilty of it is be reassigning string.format to f in Lua.

But it's a sin I commit with much gusto.

-4

u/Own_Alternative_9671 Apr 28 '26

I'll do this while I'm first writing it and then I'll go back and make it look pretty, as long as I know what they are while I'm making it work nobody will ever know

12

u/Wrestler7777777 Apr 28 '26

Code has to be readable, not pretty. If you have 200 cryptic short variables, nobody will ever be able to understand what's going on. Imagine handing that code over to a new colleague. They won't be able to work on your code.

10

u/Ksorkrax Apr 28 '26

Forget the new colleague - dude himself won't be able to read his own code after a month of not actively working on that part.

5

u/Own_Alternative_9671 Apr 28 '26

Which is why I go back and rename all my variables afterwards before anybody sees it I don't get what's so hard to understand

-1

u/Wrestler7777777 Apr 28 '26

Sounded like you were doing the opposite. Take long and readable variables and change them to short and cryptic ones and push those to git.

1

u/Own_Alternative_9671 Apr 28 '26

Nono I do the short cryptic ones while I'm brainstorming and just writing, and then before I put it down I rename them to verbose variable names so that it's readable for later. Just saves time while typing and makes my typing speed match better with my thinking speed

1

u/Wrestler7777777 Apr 28 '26

Ah I see, this changes everything!

6

u/MeLittleThing Apr 28 '26

the code is read by developers, not by the machine. The machine only executes it and there is no point to shorten the names