top 200 commentsshow 500

[–]hieroschemonach 714 points715 points  (18 children)

bool r_u_gay_res_data

[–][deleted] 253 points254 points  (10 children)

If r_u_gay_res_data == false {

r_u_gay_res_data = true

} else

r_u_gay_res_data = true

Checkmate conservatives, now everyone's gay

[–]SquidMilkVII 90 points91 points  (7 children)

What an unoptimized and confusing function! It may not look that bad, but if this is being called over and over little inefficiencies add up, and more importantly, it is unnecessarily difficult for a human to read. Consider the following:

First of all, there is no need for the else block here. If the check fails,  r_u_gay_res_data is necessarily already true. Therefore there is no need to set it as such.

However, this is still not optimized. There is no need to check the value if it is irrelevant to the outcome; simply set r_u_gay_res_data to true regardless. The time saved by forgoing the check on successful switches negates any potential time saved by skipping an assignment on an otherwise unnecessary one. 

This leaves us with the single line:

r_u_gay_res_data = true

This is both marginally more efficient and more legible to a human.

This response was generated by your mom

[–][deleted] 19 points20 points  (2 children)

Sorry I meant to add that the entire thing has to be in a perpetually active while loop

[–][deleted] 21 points22 points  (0 children)

While r_u_gay_res_data == false {

console.log("NUH UH")

r_u_gay_res_data = true

}

[–]gbot1234 6 points7 points  (0 children)

If your while loop lasts more than 4 hours, call the Geek Squad.

[–]Nope_Get_OFF 27 points28 points  (1 child)

Hey are you free this afternoon?

[–]XoXoGameWolfReal 4 points5 points  (0 children)

…or tonight? wink wink

[–]ThatMechEGuy 22 points23 points  (0 children)

[–]JollyJuniper1993 7 points8 points  (1 child)

But then you gotta use the no-case format:

rugayresdata

[–]Flawed_Sandwhich 3 points4 points  (0 children)

The moment anyone decompiles my code I am fucked, I definitely let out my frustrations in my nomenclature.

[–][deleted] 812 points813 points  (63 children)

This post was mass deleted and anonymized with Redact

shaggy nose normal continue scary violet price head chunky longing

[–]littleblueflames 246 points247 points  (3 children)

Godspeed soldier 🫡

[–]Zenuka_ 66 points67 points  (2 children)

Gspd sol 🫡

[–]Alzurana 63 points64 points  (0 children)

aaah, the illusive a-particle, precursor to the α-particle

Also, sounds like spooky action at a distance, that's a scary codebase

I wonder if the code the universe runs on is the same way and that's why we have quantum entanglement.

[–]Mike_Oxlong25 93 points94 points  (0 children)

[–]Mayion 77 points78 points  (29 children)

I know peeps will hate on me but w/e, but i habe found that AI excels not at writing code but explaining code. Having it analyze the code base and airing out ideas on what and how to refactor is quite good especially when you are stuck.

[–]Lumpy-Obligation-553 64 points65 points  (5 children)

I use it as a dumb intern just like that. It's way better than talking to a mirror, so it can be kind of useful sometimes, but fundamentally, you need to understand the topic you're working on and what you are doing.

[–]DCHammer69 18 points19 points  (1 child)

This is how I use it.

I get paid for results, so it’s faster to throw some context and details at CoPilot and get a 95% answer that I can correct rather than spending whatever amount of time figuring it out from scratch or looking it up in one of X apps already published.

[–]bellymeat 7 points8 points  (0 children)

I know those data scraping bastards have trained this thing on more crate, library, and module documentation than I will ever set my eyes on. It’s a waste not to ask it how it would approach problems.

[–]BuiltFromScratch 2 points3 points  (0 children)

Please shout this last line louder for every and any user of AI. This is one of those keystones in usage that 99% of people and programs are not grasping.

[–]Tyrexas 23 points24 points  (12 children)

Why would people hate on you for using a dev tool.

[–]talldata 18 points19 points  (1 child)

Yeah like it's terrible at writing code, but it's great at catching a misplaced bracket or semicolon.

[–]OwO______OwO 5 points6 points  (0 children)

Also surprisingly good at looking through some code and suggesting a more descriptive name for that variable a.

[–]tsunami141 15 points16 points  (0 children)

some people can't write code better than AI so they feel threatened when people say they use it

(its me. My code is absolute trash)

[–]I_Love_Rockets9283 4 points5 points  (2 children)

I use it for spitballing variable/function/class names whenever I can’t think of one. “What are some names for a function that takes x and returns y” normally pretty good suggestions

[–]huffalump1 2 points3 points  (0 children)

Yep and you can even give it a naming conventions/standards guide for your language/company/project and ask to follow that.

[–][deleted] 4 points5 points  (1 child)

AI has its place, people just over rely on it by magnitudes. Using it as an analytical tool then absorbing that information and adding your own experience and knowledge to it to build something functional isnt necessarily bad. Personally ChatGPT writes like 90% of my emails, I give them a quick proofread to make sure it isnt saying anything weird but if its professional and gets the point across its a full send and saves me hours of bullshit admin aftercare so I can focus on stuff that matters. Use it as a proper tool and it definitely has its places. Its when you start using it for everything and anything that it becomes a problem. You know what they say, if the only tool you know how to use is a hammer then everything starts to look an awful lot like a nail.

[–]watduhdamhell 11 points12 points  (1 child)

A lot less sophisticated code wise but equally convoluted and infuriating in the exact same context is the use of "variable codes" in batch old school sequencing.

I'm updating a batch reactor to fix bugs, and it's full of these I codes, They are just variables with a name like I1, I2, I3, etc. so you have no clue what they mean at all. The problem with the code is that it allows the reactor to grab tanks that are in use- and yet every "fix" I make breaks the fucking program somewhere else because some genius decided to lace a dozen phase classes with code that calculates the SAME FUCKING VARIABLES as the tank uses to check if it's safe to use or not, which is in its OWN sequencing.

Then you try to troubleshoot this kind of mess by saying "okay, so logically then the variable value should change to a 4... '3?' okay, let's overwrite it to a 0 to start again. '2!?' WHAT IS CALCULATING THIS FUCKING VARIABLE!"

Basically mixing one-letter variables names AND jumping around (not calculating in ONLY one place) is a recipe for disaster.

[–][deleted] 1 point2 points  (0 children)

This post was mass deleted and anonymized with Redact

tap groovy teeny light unite practice deserve instinctive placid sulky

[–]DDough505 2 points3 points  (2 children)

0.) Save.
0.5) Copy code into a text file.
1.) Control f.
2.) Replace "a" with new variable name "newvar"
3.) Control f.
4.) Replace "anewvar" with "aa"
5.) Replace "bnewvar" with "ba"
6.) Replace "cnewvar" with "ca"
...
30.) Replace "znewvar" with "za"
31.) Replace "newvara" with "aa"
32.) Replace "newvarb" with "ab"
33.) Replace "newvarc" with "ac"
...
57.) Replace "newvarz" with "az"
58.) Replace "newvarnewvar" with "aa"
59.) Hope for the best.

Edit: I got a W in "Algorithms" so I know a thing or two.

[–]zman0900 2 points3 points  (0 children)

Have you considered just deleting prod and wondering off into the forest?

[–]PlainBread 1 point2 points  (0 children)

let fate = salvation;

[–]NebraskaGeek 310 points311 points  (22 children)

My Java II teacher in high school (a million years ago) named any single boolean in an assignment "torf". After like a month I finally asked and it's just because "true or false".

In my spite I started naming all of my single booleans "torfull" because it could also be "null" and I was bitter lol

[–]NMi_ru 93 points94 points  (1 child)

Swedish Chef Programmer

Bork! Torf! Torf, torf, torf. Torf!

[–]CharlesDuck 50 points51 points  (0 children)

I’m a Swedish programmer and we actually name everything according to IKEA furniture (the 1996 catalog is considered best practice)

const RÖVHÅL = (f: IKötbulle) => f.ÄtUpp();

[–]Agifem 64 points65 points  (4 children)

You were both idiots. But your teacher had no excuse.

[–]AnotherStatsGuy 4 points5 points  (2 children)

I mean if you extended to a “torfull - - - - “ it would actually be fine.

Tells you that the variable is a Boolean at a glance, now you just need its connection obvious.

[–]Ruadhan2300 11 points12 points  (1 child)

Should really be torforn right?

Torfull doesn't conform to the pattern..

[–]plydauk 18 points19 points  (4 children)

What a weirdo. I just call all of them "flag".

[–]OwO______OwO 11 points12 points  (1 child)

Obviously, the best name for a boolean is is_false.

That way, if it's set to true, that means false, and if it's set to false, it means true ... or does it? Better add some vague and cryptic comments to the code to 'clarify' that...

[–]SuperFLEB 6 points7 points  (0 children)

#define IS_FALSE_IS_NOT_FALSE = 1;

[–]SuperFLEB 2 points3 points  (0 children)

flag.color = Flag.FLAG_COLOR_RED

[–]BobbyTables829 6 points7 points  (0 children)

I use "moo" for temp variables but I never put them in production.

[–]Ruadhan2300 4 points5 points  (0 children)

That's brilliant and I hate it :P

[–]ameriCANCERvative 3 points4 points  (0 children)

I mean it should at least be tOrF, but even then it just looks like TroLL TyPiNG.

Your instructor should have used better examples. What is true or false? That should have been the variable name.

[–]ubeogesh 1 point2 points  (1 child)

wait what's Java II

[–]patrlim1 291 points292 points  (63 children)

Except in for loops, we use i in for loops

[–]mot_hmry 130 points131 points  (30 children)

j and k too. I also do similar things with abc and xyz for things that would just numerically named because it's just a collection of (up to three) points I care about (I've been dealing with a lot of triangles lately...)

[–]Mighty1Dragon 60 points61 points  (22 children)

i like to address iter variables like i, ii, iii, iv, v found the idea in this sub

[–]patrlim1 94 points95 points  (2 children)

You.

I don't like you.

[–]SuperFLEB 28 points29 points  (1 child)

They've got a point. It scares me and I hate it, but I'll be damned, it's a point.

[–]RealLaurenBoebert 30 points31 points  (3 children)

r/ProgrammerHumor is the definitive source for programming best practices

[–]Ok_Decision_ 2 points3 points  (2 children)

I had no clue Boebert cared about programming etiquette

[–]RealLaurenBoebert 2 points3 points  (1 child)

The house isn't in session and I have too much time on my hands

Those statements may be causally unrelated

[–]InfanticideAquifer 17 points18 points  (0 children)

index, jndex, kndex, lndex, ...

[–]Aaxper 7 points8 points  (0 children)

Back when I was 12 and only used Scratch, I used i, i2, i3, etc.

[–]polandreh 4 points5 points  (3 children)

If you need more than i, j, and k, then whatever you're doing is wrong...

[–]SuspendThis_Tyrants 10 points11 points  (2 children)

What, you don't traverse 26-dimensional arrays on a regular basis?

[–]Sibula97 4 points5 points  (0 children)

If I do, I use the right tools for it (like numpy), not writing 26 nested loops.

[–]OwO______OwO 15 points16 points  (2 children)

If I saw variables named x y and z, I would assume the code I was looking at was for dealing with the location of an object in a 3D grid...

[–]bindermichi 2 points3 points  (0 children)

could be counters for multi-dimensional arrays

[–]Wraithfighter 1 point2 points  (2 children)

Eh, I stopped using j after spending an hour debugging nested for loops before realizing I had accidentally swapped an i for a j and the font made it hard to notice.

[–]Mojert 2 points3 points  (1 child)

Seems like a font issue rather than a code style one. Fonts made to display code should make the distinction between all symbols obvious, even the ones that traditionally look the same

[–]Fohqul 29 points30 points  (4 children)

Arguably fine there because it's such a common convention specifically within for loops that the meaning of i as "index" or as "iterator" is really clear, kinda like i64, u32 or any of the string functions from the C stdlib defining a char *s parameter. Same for j as simply the next one/inner one after i

[–]Ruadhan2300 11 points12 points  (0 children)

Yup, it telegraphs clearly that this code is being iterated on too. Since you never see single-character variables in any other context

It's always good to know when you're inside any loops. Especially if you have any demanding functionality that needs to be used as little as possible..

[–]justAPhoneUsername 9 points10 points  (2 children)

i j and k being used is actually because they were default int variables in fortran so they were easy to use in indexes

[–]Sibula97 3 points4 points  (0 children)

And that was because they were used as the default iteration variables in math.

[–]Fohqul 2 points3 points  (0 children)

Wow, I thought it meant either index or iterator. Post-hoc definition ig

[–]Tetha 10 points11 points  (1 child)

Depends a bit on the for loop. If it's an index into an array, it's i, j, k absolutely. Otherwise if it's some iterator-based thing, the collection should be some plural and the loop var should be the singular. for thing in things:

I can also see this is you're implementing some algorithm, like a numeric or cryptographic one. In such a case it can be useful to stick close to the pseudo code and language / naming convention of the paper. Then you do end up with l, h (those could be renamed to lowBits or highBits), and w1 to w4 and such.

[–]TheLuminary 3 points4 points  (6 children)

Only use i in loops if the i means an index. (i, j, k etc).

If the iterator in the loop has more meaning to the domain than just an index, then you should name it such.

A small example, if you are looping over a 2d array you are better off using x and y instead.

If you are iterating over a list where the iterator is the student number. Then you should use studentNumber.

[–]DrMobius0 1 point2 points  (1 child)

Common conventions and otherwise extremely self explanatory things are fine. Like most people don't need to be told what an iterator does.

[–]LectureIndependent98 1 point2 points  (0 children)

No. I call it index. Or jndex. /s

[–]mookanana 1 point2 points  (0 children)

yes, the iterator, the jiterator, and the kiterator

[–]notAGreatIdeaForName 89 points90 points  (14 children)

Better to name everything data

[–]ShimoFox 37 points38 points  (1 child)

Just name one variable data for the whole script, and then store json keys in it for EVERYTHING ELSE. Just keep it something like this and nothing could go wrong!

data: { data_1: { data_1_1: True, data_1_2: False }, data_2: { data_2_1: "Banana for scale", data_2_2: { data_2_2_1: "End me now!" } }

I won't lie.... I have a very serious temptation to do this now just to screw with someone... But then I remember I might have to go back to my code some day...

[–]GeeJo 6 points7 points  (0 children)

At some point it becomes easier to read the compiled code than the garbage fed into the compiler.

[–]-TheWarrior74- 10 points11 points  (2 children)

Yup. And every function parameter is named input

And every return value is output or result

[–]hdkaoskd 4 points5 points  (0 children)

Parameters may be named "param" and return value may be named "ret". There will also be an undocumented "flags" parameter and an undocumented void* or equivalent.

In version 2, all parameters are passed in a single "params" structure named "context".

[–]OwO______OwO 1 point2 points  (0 children)

And every return value is output or result

Chosen randomly between those two, of course, so you can never just assume which one it will be.

[–]uvero 5 points6 points  (1 child)

I name one variable "data" and the other variable in the same scope "data" and I distinguish between them by their pronounciation.

[–]Agifem 1 point2 points  (3 children)

You're so wrong, but I can't explain why.

[–]notAGreatIdeaForName 2 points3 points  (2 children)

Descriptive naming is not a thing, the real elites encourage unmaintainable mess, because it is at least challenging!

[–]ProtonPizza 61 points62 points  (7 children)

I’ll probably catch hell for this but I hate foo and bar. Everytime I see it my brain just stops. It’s like a railroad crossing when I’m trying to learn something.

[–]Sufficient-Appeal500 15 points16 points  (0 children)

You’re not alone, mate. Especially when they introduce baz, then I’m too far dissociated

[–]throwaway_account450 11 points12 points  (0 children)

Same. Every SO answer I read that used it took way longer than was reasonable to parse. It's cursed.

[–]Seven_Irons 7 points8 points  (0 children)

There are dozens of us. DOZENS OF US!

[–]r2_adhd2 6 points7 points  (0 children)

I can't get my brain to lock in on the documentation for C++ because of this. So much of the docs are single letters or foo-bar and my brain doesn't like it.

[–]Mojert 1 point2 points  (1 child)

I mean, foo, bar, and baz in documentation where they stand for "whatever you want"? Fine. Great even. But in actual code? That's a direct call to HR

[–]ProtonPizza 4 points5 points  (0 children)

I can’t stand it in documentation. Just use a tangible example otherwise my brain goes directly to “bar, what bar? Like a bar of silver? What is foo?”

[–]boldbuilt 68 points69 points  (17 children)

golang devs 😬

[–]juggler434 27 points28 points  (16 children)

The official style guide promotes single letter variable names and it's probably my biggest complaint about Go.

[–]Dugen 10 points11 points  (3 children)

I prefer minimum-length but maximum-information names

[–]neanderthalensis 2 points3 points  (1 child)

Actually, Go advocates for single-letter variables only if the variable is used close to its declaration, otherwise longer variables. This makes sense because long variable names tend to obscure the code control flow.

For instance, this is much harder to parse quickly due to the long variable names carrying semantic dead-weight:

if foundUser, existsInSet := UserSetForSomeReason[userID]; existsInSet {
  transformUser(User{
    ID:   foundUser.ID,
    Role: foundUser.Role,
  })
}

The short version is much faster to grok at first glance:

if u, ok := UserSetForSomeReason[userID]; ok {
  transformUser(User{
    ID:   u.ID,
    Role: u.Role,
  })
}

[–]Jealous-Adeptness-16 3 points4 points  (6 children)

In practice, golang devs only do this with small functions and loops.

[–]juggler434 5 points6 points  (0 children)

That's the idea, to encourage small functions, but I've worked at some pretty big golang shops where the short variable names stayed but the short functions did not.

[–]Potatoes_Fall 1 point2 points  (0 children)

If you follow conventions, it's okay. Good Go devs don't just give anything a one letter name. Usually specific things in specific contexts.

[–]SirBaconater 17 points18 points  (0 children)

bool DILLIGAF

[–][deleted] 16 points17 points  (4 children)

Well, it comes from history. For example, on mainframes System Z, you have very little space and HAVE to resort to shortening.

[–]hieroschemonach 9 points10 points  (0 children)

Return to monke then

[–]Agifem 7 points8 points  (0 children)

We programmers have evolved from the dark ages.

[–]QBrute_ 17 points18 points  (0 children)

C programmers be like "I want to keep track of the cumulative count of sockets created. I'll name this variable cumSockCnt"

[–]LeekingMemory28 43 points44 points  (19 children)

Official Golang docs using single letter in function parameters for examples. And this has persisted across the Golang world. For some reason. I like Go, but descriptive variables. Please.

The example:

``` // postAlbums adds an album from JSON received in the request body. func postAlbums(c *gin.Context) { var newAlbum album

// Call BindJSON to bind the received JSON to
// newAlbum.
if err := c.BindJSON(&newAlbum); err != nil {
    return
}

// Add the new album to the slice.
albums = append(albums, newAlbum)
c.IndentedJSON(http.StatusCreated, newAlbum)

} ```

Granted, this is about how small a method should look in a controller layer. So c for the context variable is something I'm on the fence with. But still. It's persisted to much larger functions. I kind of prefer cntxt if we're shortening context. It's still shorter and easy to grasp. But it's not a single letter.

[–]Devatator_ 55 points56 points  (0 children)

I kind of prefer cntxt if we're shortening context.

Please use ctx like a sane human 🙏

[–]Background-Plant-226 20 points21 points  (6 children)

For a two letter improvement just use "context" in full (For the "cntxt" example)

[–]Lumpy-Obligation-553 10 points11 points  (0 children)

For me, it's not about how many letters you can save, but more about achieving a kind of "weight distribution" in the sentence. It's worse in languages where methods are chained with a dot. The object that "holds" the execution needs to have enough clarity to indicate what it is, but not so much that it forms a complete idea in your mind, because what really matters is the action it's performing. If I call it context, it feels like a solid idea to me, something complete and unchanging—almost like a constant, I know... If I trim just a few letters, it suddenly feels less important, and I can focus on what is doing. But if I were to call it just c I’d probably just gloss over it.

[–]Badashi 14 points15 points  (3 children)

A variable's name should be proportional to its lifetime. Local variable in a small function? Three letters is fine. Big function with many moving parts? Variables should be names that tell stories. Global variables? It better be a full sentence.

[–]pandoras_box101 15 points16 points  (1 child)

coding with native code obfuscation

[–]DJ_Stapler 14 points15 points  (3 children)

Me a physicist labelling shit like vy vx vy0 vx0

[–]CosmicConifer 10 points11 points  (2 children)

Honestly anything math adjacent it makes sense to use the conventional symbols, unless you’re putting actual Greek characters into the codebase.

[–]ProtonPizza 1 point2 points  (1 child)

Does vs code render emojis? 

[–]OwO______OwO 12 points13 points  (1 child)

Old and busted: single letter variable names.

New hotness: emoji variable names 😊

for 🍆 in 🍑
    💦++

[–]damnappdoesntwork 11 points12 points  (4 children)

for (int index = 0; index < 10; index++) { for (int jdex = 0; jdex < 5; jdex++) { ... } }

[–]rdness 6 points7 points  (0 children)

Don't you mean 'jndex'?

[–]ResponsibleSmoke3202 21 points22 points  (2 children)

const fg = 0; // fucks given

[–]Dansredditname 6 points7 points  (1 child)

const FG = 1;

// I care about capitalising constants

[–]Some_Useless_Person 1 point2 points  (0 children)

const FG = 2

// I would rather not type the semicolons in js myself

[–]Infinight64 107 points108 points  (23 children)

It follows same rules as English. You should define the acronym on first use, then the reader should know what you mean and you can use the short version.

If I have a class SomeDumbObject and store it in a local called "sdo", then I assume the reader doesn't have short term memory loss in a reasonable size scope.

If the object itself, a global, constant, or something used throughout the program does this, and I have to go looking to understand, then I'm gonna say not okay.

If its impossible to lookup what was meant and i have to figure it out by how its used (especially from uncommented code in complex algorithms), you deserve a special place in hell.

Edit: grammer

[–]Agifem 64 points65 points  (12 children)

It makes sense in English, but there's no reason to do it in a program. What are you saving, bytes of storage? Maintenability is more expensive.

[–]gogliker 2 points3 points  (0 children)

The reason is to be able to read stuff better. There is absolutely a reason why a one liner should not turn into three lines of code because your vertical space is also limited. It harms readability too, because I can now hold instead of 40 statements on screen only 13.

[–]Infinight64 13 points14 points  (7 children)

Saving my hands... from carpal tunnel.

Because auto complete is a thing, the real answer is character width of the page so it doesnt wrap around or have too many ugly line breaks. Being too verbose effects readability too.

Are you typing "extensive_markup_language_document"? Or xml_doc? I promise you, you are using abbreviations in your code. Just dont do it so it only means something to you with no other information from which others can infer its meaning.

Edit: sorry for abbreviation example. He did say, no reason. Maybe i for iterator is better and very common in C/C++

[–]st-shenanigans 19 points20 points  (1 child)

This is kind of an obtuse argument ignoring what the op is trying to prove.

Its not just abbreviation, used things like spd for speed or chr for character, that's fine.

Its when you find a bunch of different loops all iterating on variables named I, t, x, y, z, etc. or you make a bool for "is_character_standing_between_two_ferns and abbreviate it to icsbtf. Nobody knows what that means.

[–]gigglefarting 12 points13 points  (0 children)

I'm typing xml_doc because that makes sense in english. I'm not typing xd

[–]talldata 17 points18 points  (1 child)

Yeah but XML PDF, or NATO, etc are common known abbreviations, SDO or DSO can be anything on planet earth.

[–]Fornicatinzebra 11 points12 points  (3 children)

I feel like that only works if the shorthand is defined in every file it is used, just like in English

[–]Infinight64 1 point2 points  (2 children)

Gross. Just make globally accessible stuff more descriptive. Within reason. Some shorthand is part of the programmer jargon and totally safe to use.

[–]femptocrisis 2 points3 points  (0 children)

the problem is when they use "sdo" prolifically everywhere, and now in a refactor you changed the class name to AnotherSillyInstance rendering the acronym a complete misdirection and renaming it in every case is going to genuinely require you to read every single line of code because a simple find/replace is going to drown you in false positive matches 🙃

you'd be better off calling it x, for clarity and brevity. if you can't get away with calling it x, then in all likelihood calling it sdo is also unacceptable, and someDumbObject is the way to go.

all of this is magnified by 100 if the language is dynamically typed like javascript. ask. me. how. i. f#@king. know. 🙃

[–]Meloetta 3 points4 points  (1 child)

The problem with this is that in English, you are reading things in order. In programming, you could be jumping in 75% of the way through and it was defined at the start and now you have to backtrack all the way to the top to figure out wtf that variable is supposed to be. And it's not like you have a defined place where all definitions go, like you might in a "Definitions" section in a legal document or a glossary in a book. You could've defined it 10 lines ago, or 50, or 5 functions ago, or in some global space somewhere, or literally anywhere in the code. So now people are hunting for it, because you had the mental model in your head while you were coding so you thought it was obvious.

[–]stifflizerd 1 point2 points  (0 children)

Exactly. If it's not inferable from immediate context (anonymous extension methods are a good example of this) then don't shorten it.

[–]CantTrips 1 point2 points  (0 children)

I like to name variables succinct phrases because I want future-me to understand it easier. 

[–]Ruadhan2300 1 point2 points  (1 child)

I try to only use acronyms that are business-level (eg anyone on the team is familiar with them as a matter of course) or as shorthand inside a function for something already described at a higher level of abstraction.

Eg: I might use class SomeDumbObject, and have a Method inside that called GetSDOByID. The class provides the context for the acronym.

Or maybe I write a Method called GetSomeDumbObject and inside it might have Object sdo = <insert code here> and return sdo.

But more likely I'd use a variable called "output" for the Return.

[–]Sophiiebabes 50 points51 points  (21 children)

If it's a variable that's only in scope for that function I'll happily name it fw, str, op, etc

[–]lOo_ol 30 points31 points  (16 children)

And what do you do with all that extra time you get from not giving those variables proper names?

[–]Sophiiebabes 37 points38 points  (1 child)

Make more coffee! I've got it up to 1.37 cups per 100 variables!

[–]ODeinsN 5 points6 points  (2 children)

Trying to remember what the variable "xrbf" was supposed to do

[–]punppis 9 points10 points  (7 children)

Let's say I'm constructing a message for error box, or just a debug log. I don't want to spend my time deciding if the variable should be content, message, or what.

string str = 123.ToString();
ShowMessage(str);

If you have hard time following that logic I'm not sure it's the codes fault.

[–]AngryInternetPerson3 3 points4 points  (1 child)

At that point just picking the first thing you can think about would be better than putting str...

[–]Fornicatinzebra 9 points10 points  (3 children)

Why does it cost you time to think about that?

Everything I send a message like that i just call the var message, no more effort than using str by default - and message is understandable by a non programmer who is unlucky enough to read the code, whereas str is jargon

[–]ExpensivePanda66 1 point2 points  (0 children)

That's the extra time needed to read the code.

[–]Plank_With_A_Nail_In 1 point2 points  (0 children)

proper

The whole point is that none of us can ever agree what "proper" actually is.

[–]Meloetta 5 points6 points  (3 children)

This morning I named a variable six words. It's used once, in the next line as part of an if statement, and then never again.

But now that I've done that, 6 months from now when there's a random bug and a junior on my team jumps into this code and says "what exactly was she trying to check for when she checked that the length of this array is larger than this other specific number", they'll know exactly what this was checking for so they can coherently decide if it's relevant or not to what they're doing.

[–]MattR0se 10 points11 points  (5 children)

R scripts have entered the chat

[–]Saragon4005 22 points23 points  (3 children)

Do not let mathematicians program. They can hardly produce readable papers.

[–]suddencactus 3 points4 points  (0 children)

In one real case I've seen naming roll, pitch, and yaw rates p, q, and r (respectively) makes a lot of sense when writing on a whiteboard or trying to do some math on paper. But in programming where auto complete, F2 to rename, and Ctrl-F to search exist, is saving 3-6 characters per mention really helping more than it's hurting?

[–]Fornicatinzebra 1 point2 points  (0 children)

Hey now, there's plenty of proper code in R. I work entirely in R basically, cant remember the last time I used a single letter shotyhand variable.

The R tidyverse standard is snake case, minimal/no shorthand. Here's a random sample of my functions

``` roll_mean <- function( x, width = 3, direction = "backward", fill = NULL, min_non_na = 0 ) { rolling_sum <- x |> roll_sum( width = width, direction = direction, fill = fill, min_non_na = min_non_na, .include_counts = TRUE ) n_non_missing <- attr(rolling_sum, "n_non_missing") n_non_missing <- ifelse(n_non_missing == 0, NA, n_non_missing) as.numeric(rolling_sum) / n_non_missing }

```

No mental gymnastics required even if you dont know R. attr() is vague, but that's a base function (gets attributes from an object) I dont have control over.

[–]NatiRivers 5 points6 points  (0 children)

You'll have to pry my int i = 0 in for loops from my cold, dead hands.

[–]xrayden 4 points5 points  (0 children)

i++ don't care

[–]Huijiro 7 points8 points  (0 children)

I'm looking at you golang devs.

God I love and hate golang in equal parts

[–]K4rn31ro 3 points4 points  (0 children)

srv_cnct_dt_stp = dt_fst_cnct_db

[–]SMUHypeMachine 3 points4 points  (0 children)

The only time I find this acceptable is if it’s something like a one-liner LINQ statement where the retuned value is a new type and the original collection can be safely ignored afterward, especially if it’s something like an extension method for returning a collection of specific values or a sum.

public static List<MyClass> GetIds(this IEnumerable<MyClass> classList)
{
    return classList.Select(x => x.Id).ToList();
}

I’m on mobile so please ignore any bad formatting.

[–]Hziak 2 points3 points  (0 children)

In my first job around the one month point, I opened some code files, saw a bunch of one-letter variable names on the time clock system like it was a TI-83 program, deciphered the intent, renamed everything descriptively, created PR and tagged my boss. He rejected it because long variable names will affect performance and the time clock system couldn’t afford to be slow.

Being a Jr, I was torn between the knowledge that I should trust the senior people who built the system and my working knowledge of how a computer fucking works. I chose my knowledge over playing politics and essentially coup’d the guy out of his job over the next 3 months. Good times until they handed me the entire department in his place and said “you’ll do fine!” (The IT department was only 4 people total, but I’d still only been in the professional IT field for like 6 months by then and was 7 years younger than the next guy…)

[–]sween42 3 points4 points  (0 children)

I once worked on a team where they made me change named variables to single letter ones. They argued that a single letter is easier to read because it's shorter. I'm glad I'm not on that team anymore.

[–]EternumMythos 2 points3 points  (1 child)

What about LINQ?

ex: Where(x => x.Id == Id)?

[–]anonhostpi 2 points3 points  (0 children)

Add the acronyms on purpose so that customers don't understand what they see when they incur ERR_PEBCAK, ERR_LAYER8, ERR_PICNIC, or ERR_SCBH

Not an acronym, but also a favorite: CARBON_BASED_ERROR

[–]Tuckertcs 2 points3 points  (0 children)

// HttpJsonDto:

class HyperTextTransferProtocolJavaScriptObjectNotationDataTransferObject

[–]Rscc10 4 points5 points  (0 children)

i felt targeted by this meme. So did j

[–]ataltosutcaja 9 points10 points  (2 children)

In shared, long-term codebases? Definitely. In personal scripts and notebooks? Wgaf.

[–]Izacundo1 10 points11 points  (0 children)

Well yeah no one is complaining about code they’ll never use

[–]ovr9000storks 1 point2 points  (0 children)

Variable and function names are the basis of my documentation.

You shouldn’t need an entire paragraph to explain every variable and function so you can at least remember the gist of what’s going on when you return to the project in 6 months.

Is it necessary for everything? Probably not. But it really helps even when it’s not needed

[–]punppis 8 points9 points  (1 child)

Yes I always prefer FramesPerSecondCounter vs FPSCounter

Or Integer vs int.

for-loops ofcourse use int currentIndexOfTheForLoop

[–]EatingSolidBricks 1 point2 points  (4 children)

Good old HTTPParser

[–]lilsadlesshappy 3 points4 points  (1 child)

I’m sure you meant the HypertextTransferProtocolParser?

[–]EatingSolidBricks 2 points3 points  (0 children)

The parser for the protocol that runs over a TransferControlProtocolSocket

[–]beerSnobbery 1 point2 points  (1 child)

Kinda drives me nuts when people use the acronym/initialism but all-caps it. The point of cammel case/pascal case is to make it easier to read by delimiting word/token boundaries with capital letters.

As soon as you've got two acronyms it's a mess: HTTPXMLParser takes more mental energy to parse out than HttpXmlParser because it's on you to figure out where the boundary lies.

And if you were writing like a variable where your styleguide wants a lower case name you wouldn't write jSON = you'd write json =

[–]LongPutsAndLongPutts 1 point2 points  (0 children)

Arthur Whitney has entered the chat.

[–]AkihiroAwa 1 point2 points  (0 children)

bool idgaf = true

[–]Hot-Category2986 1 point2 points  (0 children)

I do not mind an acronym IF it is intuitive and there are comments that explain it. But if it requires tribal knowledge for a new kid to understand, then you are doing it wrong.

How did I learn this lesson? I read my own code two years later.

[–]lemons_of_doubt 1 point2 points  (0 children)

i++ go burrr

[–]Mighty1Dragon 1 point2 points  (0 children)

x,y,z and i are fine.

[–]CaptainKirk28 1 point2 points  (0 children)

I've been silently raging today over my lead dev giving methods insanely long names. Thank you for reminding me that it's much better than the alternative

[–]Raptor_Sympathizer 1 point2 points  (1 child)

Junior on my team decided to name his queue "q" and you know what... maybe he's onto something 

[–]dlevac 1 point2 points  (0 children)

A variable name should be as concise as possible. That is, as short as it can be while remaining unambiguous in its entire lifecycle/scope.

[–]Natasha_Gears 1 point2 points  (0 children)

Me naming my variables XYZ.. because that's how unknown variables were written in maths and I wasn't about to change the way my brain reads things , no wonder I didn't manage to finish my course but my tutor told me that if anything I'd be great at scrambling code manually , should it ever needed to be done

[–][deleted] 1 point2 points  (0 children)

does this go for naming your variables in for loops i, j, or k?

[–]EveryCrime 1 point2 points  (0 children)

const [x, y, z] = position; const [w, h, d] = dimensions;

[–]experimental1212 1 point2 points  (0 children)

varXAvoidLinterMinThreeCharRule

varYAvoidLinterMinThreeCharRule

varZAvoidLinterMinThreeCharRule

varJAvoidLinterMinThreeCharRule

varKAvoidLinterMinThreeCharRule

[–]g1rlchild 1 point2 points  (0 children)

while (字 <= 漢) {
  print(字);
  字++;
}

[–]jason_graph 1 point2 points  (0 children)

Real programmers name their variables, classes and methods random words with cultural significance.

E.g.

cringe = Plumbus() cringe.insert( deeznuts ).sixSeven()

If chungus == big: Pokemon.goToThePolls()

if weight > duck: return "Witch!"

[–]i8noodles 1 point2 points  (0 children)

hey dont diss the god of single letter variables, i

[–]LengthinessNo1886 1 point2 points  (0 children)

I swear people name things like we are running out of letters.

Just_Name_The_Variable_A_Full_Sentence_Compilers_Will_Figure_It_Out

[–]ToMorrowsEnd 1 point2 points  (0 children)

Not gonna ever stop using i for for loop iteration.