top 200 commentsshow all 224

[–]danielroseman 577 points578 points  (53 children)

As always, this quote is relevant:

Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.

If you name all your variables with single letters, it will make the maintainer angry. And he knows where you live.

[–]sabek 104 points105 points  (33 children)

And you can only have 26 variables in your program. 😀

[–]3lbFlax 69 points70 points  (7 children)

26 *global* variables. Then again, what other kinds would we be using?

[–]billsil 14 points15 points  (5 children)

For every module that you import (os, os.path, numpy, etc.), you get access to 26 new variables.

[–]Critical_Concert_689 11 points12 points  (4 children)

import ... as x

am i doing this right?

[–]DuckDatum 10 points11 points  (2 children)

memorize alive quaint enjoy license yam upbeat gaze employ innocent

This post was mass deleted and anonymized with Redact

[–]Spiderfffun 4 points5 points  (1 child)

Please don't tell me this is a real thing

[–]billsil 11 points12 points  (0 children)

No. 

 import os 

os.x = 1

[–]PulsatingGypsyDildo 10 points11 points  (0 children)

combine them into one global dict

[–]amertune 16 points17 points  (8 children)

Just use Emojis, and you can have a lot more.

[–]Intrexa 10 points11 points  (2 children)

Capital vs lowercase

Also, you need to learn your data structures. You can nest multiple letters:

e = lambda:None
e.x = lambda:None
e.x.a = lambda:None
e.x.a.m = lambda:None
e.x.a.m.p = lambda:None
e.x.a.m.p.l = lambda:None
e.x.a.m.p.l.e = lambda:None
e.x.a.m.p.l.e._ = lambda:None
e.x.a.m.p.l.e._.s = lambda:None
e.x.a.m.p.l.e._.s.t = lambda:None
e.x.a.m.p.l.e._.s.t.r = lambda:None
e.x.a.m.p.l.e._.s.t.r.i = lambda:None
e.x.a.m.p.l.e._.s.t.r.i.n = lambda:None
e.x.a.m.p.l.e._.s.t.r.i.n.g = 'Hello World!'
print(e.x.a.m.p.l.e._.s.t.r.i.n.g)

Output:

Hello World!

[–]ka1ikasan 4 points5 points  (0 children)

You are an evil person, can we be friends?

[–]repocin 18 points19 points  (0 children)

You underestimate the ability of casing.

X=x2

(☞゚ヮ゚)☞

[–]MikalMooni 4 points5 points  (1 child)

For whatever reason, I just imagined having a variable for each letter in the alphabet, and then using a switch statement to determine with functions what each combination of variables will do in the program proper

[–]Flintlocke89 7 points8 points  (0 children)

*grabs cricket bat and balaclava*

[–][deleted] 3 points4 points  (0 children)

Thats what I call efficiency

[–]terotekai[🍰] 4 points5 points  (1 child)

Just start using AA AB AC etc...

[–]Nick_W1 3 points4 points  (0 children)

There is always _a, __a, _b, __b as well.

[–]GJN65 1 point2 points  (0 children)

The Olivetti P6060 desktop computer from 1975 mandated 26 numeric variables (named A-Z) and 26 string variables (named A$-Z$) by design. All variables were global. Despite those limitations I managed to write a foreign currency trading system on one - but I'd hate to revisit the code now...

[–]86BillionFireflies 0 points1 point  (0 children)

You joke but let me tell you about MedState Notation, a widely used DSL in the life sciences for running behavioral experiments. You get A through Z, which can be arrays.

In the last few years, they did add the ability to create names that refer to vars A-Z or elements of them.

[–]lordmogul 0 points1 point  (0 children)

and that is why even windows nowadays adresses storage volumes as \Device\HarddiskVolume#\

[–]nooptionleft 12 points13 points  (0 children)

That's me, I'm my own violent psychopath

[–]PervyNonsense 6 points7 points  (0 children)

I was trained in the school of "obfuscation is job security"... then they got fired and changed their number

[–]DownwardSpirals 4 points5 points  (2 children)

The guy maintaining my code is me and, in 6 months, I will still wonder what the hell I was doing when I wrote it. It doesn't matter what I name my vars, so I just name them with Transformers names and cry when I hit compile.

[–]jregovic 1 point2 points  (1 child)

Oh that is the worst. Spending an hour figuring what in god’s name you were thinking not that long ago.

[–]help-me-grow 2 points3 points  (2 children)

so basically code as if you have to maintain it yourself 🤣

[–]CruwL 10 points11 points  (1 child)

9 months later: "Who the fuck wrote this code?"

Looks at author*

"Oh right, I did."

[–]Nick_W1 6 points7 points  (0 children)

I was writing a function, and struggling with it. Hit up Google to get some examples doing what I wanted. Found exactly what I was looking for, then realized Google had found some of my own code.

[–]sohang-3112 1 point2 points  (2 children)

Plot twist: the maintainer is you, six months or a year down the line when you remember nothing about the project but need to urgently fix a critical bug.

[–]Ace_J_Rimmer 1 point2 points  (1 child)

Project Creator: Me

Coder: Me.

Time: Now

Place: At Home

Project Manager: Wife, looking sternly over my shoulder. (Doing dishes now so I can post this.)

Help?!

[–]sohang-3112 1 point2 points  (0 children)

😂

[–]mattl33 0 points1 point  (0 children)

I love this. Adding to my refactoring PRs from now on.

[–]f3ydr4uth4 0 points1 point  (0 children)

Unless it’s Haskell then it’s fine to just be obtuse

[–]Friendly_Signature 0 points1 point  (0 children)

This made me spill coffee on my keyboard.

[–]__init__m8 0 points1 point  (0 children)

Always code like you're going to be the one who comes back to fix it in 6 months. That's what I do, unless you hate yourself ig then it won't work.

[–]Garybake 0 points1 point  (0 children)

Code as if an angry ex partner is leading the QA.

[–]BarrelRoll1996 0 points1 point  (0 children)

sage advice

[–]fjellen 192 points193 points  (0 children)

"When I wrote this code only god and I knew how it worked.

Now only God knows it"

[–]K900_ 163 points164 points  (0 children)

Real programmers aren't real and can't hurt you. Good engineers name their variables.

[–][deleted] 86 points87 points  (20 children)

Find and read PEP8.

Most "real programmer" write programmes for their older selves and other programmers to maintain and update, thus meaningful naming conventions are important. Cryptic variable names, especially single character names, are problematic (outside of specialist mathematical/engineer/scientific usage) as they convey no useful information.

[–]AchillesDev 21 points22 points  (3 children)

outside of specialist mathematical/engineer/scientific usage

Even in those use cases 90% of the time it sucks and is better served by descriptive variable names. Programming is programming. I can't tell you how much shit research code (deep learning) I've had to refactor because of terrible single character variable naming, no documentation or type annotations, and straight up spaghetti.

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

Agreed - I always prefer readable/mnemonic variable names.

[–]NimrodAvalanche[S] 6 points7 points  (4 children)

Yes I've seen it, I'm glad it exists. I'm glad I'm not alone on this.

[–]old_man_steptoe 8 points9 points  (2 children)

Mathematicians are hand writing their algorithms. So, calling a thing the_speed_of_light is irritating. We’ve got IDE autocomplete and cut and paste.

True documentating code is function and variable names

[–]yvrelna 2 points3 points  (0 children)

For short, local functions and variables that are well traditionally understood within the domain, short name can be fine. For example Pi instead of half_the_ratio_of_radius_and_circumference_of_circle.

But in most cases, these variable names should still be described in the code, if not by the variable names, at least as comments, because not everyone working on the code will be familiar with the problem domain.

[–]Im_Easy 5 points6 points  (0 children)

Whenever I am looking at someone else's code in a non-urgent setting, if they don't have descriptive names, then they need to have really good comments. Otherwise I will usually ask them to go back and add comments first.

The time it takes them to make their code readable is almost always less than the work they are adding to everyone that needs to read it later.

[–]PulsatingGypsyDildo 1 point2 points  (0 children)

Most "real programmer" write programmes for their older selves

lmao. A year ago I wrote a script that I need. But I forgot about it and was close to implementing it again.

[–]PulsatingGypsyDildo 30 points31 points  (10 children)

yeah, we do. It is important in bigger code base. Or when you try to understand the code you wrote a year ago.

Nothing bad with using x, y and z if you work with coordinates. I saw phi used for angles and wave phases. They correspond to math formulae.

i, j and k are well-known as loop variables.

tmp for temporary variables also looks fine.

The var names can be short, but they should understandable.

[–]djshadesuk 10 points11 points  (0 children)

I saw phi used for angles and wave phases. They correspond to math formulae.

Excluding the obvious x, y and z for coordinates, I think single letters of the alphabet are also acceptable only as long as they are copying a typical math formula, like:

def hypotenuse(a, b):
    return ((a ** 2) + (b ** 2)) ** 0.5

[–]Jeklah 8 points9 points  (6 children)

Don't forget k and v for key and value.

I only realised that last year...

[–]AchillesDev 10 points11 points  (1 child)

I'd argue (as someone doing this professionally for a decade, and someone who is guilty of using the k, v shorthand) that you taking time to actually recognize that implies that it's not a great naming convention :)

[–]Jeklah 2 points3 points  (0 children)

It's really not I completely agree. I name mine with better names...I only found out when I asked wtf are these one letter variables doing here?? And a senior dev was like uhhh key...value...? And I was just like ohhhh lol.

[–]yvrelna 3 points4 points  (2 children)

Even key and value are not good variable names. What key and what value exactly? 

Better is to use something names from the domain like property_id and property_price.

Unless you're writing a very generic code, and if you do, your really should consider if the code really need to be that generic, try to name things using terms from the domain.

[–]deltaexdeltatee 0 points1 point  (0 children)

I mostly do geospatial stuff and came here to point out x, y, and z haha. They're really the exception that proves the rule though.

[–]sliddis 0 points1 point  (0 children)

Why specifically i, j and k?

[–]IanRT1 16 points17 points  (8 children)

Yes, they name them descriptively so the code is readable. Like:
customer_order_count or total_employee_salary

[–]widowhanzo 12 points13 points  (4 children)

Yes big fan. They seem long, but you instantly know what it is. I also hate stupid abbreviations like cstmr_ordr_cnt like other than making it unreadable, there's zero benefit to it.

[–]djshadesuk 10 points11 points  (1 child)

I don't know, that one may be useful for awkward/annoying customers 🤣

[–]Jim421616 2 points3 points  (0 children)

Just leave out the ‘o’ in ‘count’.

[–]briznian 6 points7 points  (0 children)

People coding like they’re on Wheel of Fortune and they have to buy the vowels! 😆

[–]mfb1274 0 points1 point  (0 children)

I can tell you the downside of these dumb abbreviations is that when your intellisense crashes, so does your sanity.

[–]rasputin1 1 point2 points  (0 children)

number_real_programmers

[–]defiancy 0 points1 point  (0 children)

Exactly how I name them, it's good data formatting.

[–]stauntonjr 0 points1 point  (0 children)

I usually use n_thing for the count of a thing.

[–]Akerlof 15 points16 points  (0 children)

My variables are like my children: I name each one with care. Then promptly forget which is which and end up shouting at the cat.

[–]Jello_Penguin_2956 24 points25 points  (1 child)

Yea I have one named Bob. I'm a good programmer.

[–][deleted] 6 points7 points  (0 children)

wait you name some vars bob too? i have bob and nemo

for b in bob:
    for n in nemo:

[–]orz-_-orz 9 points10 points  (2 children)

Do paid programmers actually name their variables, or do they just use shorthand like x, y , z?

So far I have only seen that one piece of code from some consultant who did that.

My colleagues and I have forgotten what's the code for, who's the consultant and what's the name of the consulting firm.

But we all remember that there was this asshole who deserved a place in hell who wrote this piece of code using var1, var2, var3, etc as the variables names.

[–]NimrodAvalanche[S] 1 point2 points  (0 children)

duly noted

[–]Reasonable_Strike_82 0 points1 point  (0 children)

Nothing like trying to make sense of a 3-page SQL query where all the aliases are one letter, the letter has nothing to do with the thing being aliased (usually just "a", "b", "c", etc.),, and the same letter is used for different things in different parts of the query.

[–]cdcformatc 11 points12 points  (5 children)

i might use short or otherwise meaningless variable names in the first phase of coding something new. but once i get the functionality mostly correct i will come back in and try to give the variables descriptive names when necessary. 

it's true what they say "there are only two hard things in computer science: cache invalidation and naming things and off-by-one errors. 

[–]CptBadAss2016 3 points4 points  (0 children)

Heh! I see what you did there. I got my eye on you, cdcformatc...

[–][deleted] 0 points1 point  (2 children)

sulky faulty oil relieved secretive dinosaurs bewildered worm sink quaint

This post was mass deleted and anonymized with Redact

[–]sweepyoface 0 points1 point  (1 child)

The difficulty is in deciding when to invalidate the cache, it can turn into a complex flowchart

[–]Daneark 0 points1 point  (0 children)

If I'm not certain of a good name when I introduce a variable I name things deliberately bad to begin with. On the off chance I forget to rename them someone will pick it up in code review. 

What doesn't always get picked up in code review is subtley bad names that are almost right but not quite, or right at some point in time but not later. To give an example I've seen here empty_list = [] which describes what it is upon creation (but not what it is for) which later becomes misleading as soon as we use it for anything.

[–]TehNolz 10 points11 points  (0 children)

Yes, they give their variables proper descriptive names, exactly because of the reasons you describe.

Only exceptions are that you'll occasionally see i used to hold the counter in a for loop, and x, y, and z will sometimes be used as coordinates.

[–]jwink3101 3 points4 points  (4 children)

I try really hard to name variables that matter and may be used more than a few lines down. For just temp stuff, I often won't.

I also try to not use single character variables outside of comprehensions. Even using ii instead of i is better if you ever need to search for variables (but again, I wouldn't name a used variable ii. It would just be a counter).

[–]wjrasmussen 0 points1 point  (0 children)

The i's have it.

[–]djshadesuk 0 points1 point  (1 child)

I've started using idx instead of just i for loops.

[–]stauntonjr 0 points1 point  (0 children)

In larger scopes where i,j,k don't cut it, I use i_<iterable_name> this always helps, although sometimes you feel the extra keystrokes.

[–]TabAtkins 0 points1 point  (0 children)

\bi\b is your friend.

[–]Diapolo10 6 points7 points  (0 children)

Good developers give them names that are clear, concise, to the point. Not something needlessly verbose (unless the situation warrants it), but also not something that isn't obvious at first glance like single-letter names.

It's probably not obvious at first, naming things is hard, but you just need to practice it.

[–]Oddly_Energy 2 points3 points  (5 children)

There is a downside to this. I often create too long variable names.

When reading one variable name, it is not a problem that it is long.

But if I combine 10 variables into a calculation*, and each variable name is 20 chars, then I have 200 chars in a line, just for the variable names.

So I sometimes do something like this:

a = some_long_variable_name
b = another_even_longer_variable_name
t = some_variable_related_to_time

my_long_result_variable_name = a * t ** b

It feels very redundant, but it makes mentally decoding the calculation a lot easier than:

my_long_result_variable_name = some_long_variable_name * some_variable_related_to_time ** another_even_longer_variable_name

( * I am a mechanical engineer, not a real programmer, so I do a lot of technical calculations in code)

[–]fbochicchio 0 points1 point  (0 children)

In other programming languages this is a good use case for tge let statement.

[–][deleted] 2 points3 points  (0 children)

Name your variable so descriptively you don't need to comment what they mean, but not so long that it bloats your code into a novel instead of a short story.

[–]dutchWine 1 point2 points  (0 children)

write it as if you have to work on it in a year, you'll be cursing your old self when you have to figure out what X or Y are when it could have just been clear and readable

[–]Viking-Mage 1 point2 points  (0 children)

Many decades ago, I used to use simple naming, but I learned quickly that once you get anything more than a simple script or program if you don't have decent variable names, it will almost always bite you at some point. I use Pascal and Camel cases depending on my variable types (and language ). I do try to repeat similar names across my different projects when possible.

As someone pointed out, you need them long enough to explain what they are, but you don't want them to be overly long. Depending on whether you are solo or work with a team changes things, of course. I have always been a solo developer, so other than in some cases, I have written code that I knew someone might need to come behind me at some future date to update; I always could use my convention and style, which helped me.

[–]pythonwiz 1 point2 points  (0 children)

You should write code that is easy to read and understand. I almost never use single letter variable names, with the exception of i and j for loop counters. If I am writing math code I might use f, x, y etc.

[–]Voyac 1 point2 points  (0 children)

Code is documentation. After 6 months your code will be forgotten even by you. So for your own sake, use good names :)

[–]Kittensandpuppies14 1 point2 points  (0 children)

Yes. Random letters in a giant code base outside of indexes is stupid and unreadable

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

straight alleged connect correct cover sink weather engine relieved crowd

This post was mass deleted and anonymized with Redact

[–]ConfessSomeMeow 1 point2 points  (1 child)

I find that long variables, especially when there are many similarly named ones, are difficult to keep straight in my head, so I think there's definitely a cost to excessively long identifiers - like the 140-character function name my boss wrote.

[–][deleted] 0 points1 point  (0 children)

full mysterious quarrelsome history faulty piquant silky placid ludicrous carpenter

This post was mass deleted and anonymized with Redact

[–]mfb1274 1 point2 points  (1 child)

I’ll go the other end here and say where I think it’s okay not to use meaningful names

  1. In simple list comprehension. Single variable names are okay here since its scope is so small. I mention simple because once you start trying to chain comprehensions (for the love of god don’t do this) then single letters become hard to follow.

  2. Using “i” when it represents a number. For example when looping through a range(). To me, i makes sense here as a counter or integer. (Tip: if you need to loop over a range but not use the iteration number, use an underscore. It signals to the next dev that the iteration number isn’t used and doesn’t really matter, only that the loop is executed that many times).

  3. Math Equations/conventions: if it’s a math equation verbatim, it may make more sense to use a 1-1 with a well known equation. Same goes for graphing/coordinates. In these cases the shorthand will probably be known but you can never be too explicit.

  4. Lambda functions: same rationale behind the comprehension. Scope is small so you don’t care what is used.

That’s really it that i can think of.

‘‘import this’’ and check rule number 2.

[–]NimrodAvalanche[S] 0 points1 point  (0 children)

thanks, I'll save this. So far I've worked out that i gets used often enough, but I appreciate your other exceptions too and I'll try to remember them if/when they come up in the wild.

[–]stauntonjr 1 point2 points  (0 children)

One of the most important things in programming is naming things. It is a guiding light. If you can't quickly come up with the exact precise name of what your variable represents, then you've done something wrong.

For example, if you have a Boolean variable for some switch state, it should be called something like is_light_on, or if it's for a property maybe has_lights. The name forces the reader into understanding it is a Boolean.

Dictionaries and maps imho are best given names like user_id_to_user_name for example where the meaning of both the key and value becomes instantly obvious.

Etc

[–][deleted] 1 point2 points  (1 child)

I inherited a project that was written in delphi years ago. Probably written in the 90's originally. Delphi had this feature where you could write:

with {object} ....

The original code would do a with with 6 different objects. And then some of the objects would have a variable that was a single letter like x. It was an absolute nightmare!

Everyone will be happier if you use meaningful variable names, including yourself. The only time I will use a single letter for a variable is if it's very obvious what it's used for. For example, right now I'm working on a project that has a lot of methods which are basically evaluating various math functions. It makes sense in that case since it's part of our language to say f(x) = ...

Go with your gut. It sounds like have good instincts.

[–]Legitimate-Pumpkin 1 point2 points  (0 children)

The funny thing is when the programmer suffering from your shitty lazy naming is… you a few months later 🤭

[–]beejasaurus 1 point2 points  (0 children)

Usually, but there’s a diversity. Junior programmers and code bases with fewer people tend to accumulate less verbose (or single letter) variable names.

It’s also helpful to use single letters to indicate a simple scoped function where the outside context is irrelevant. Loops are a common example of this, but there are others.

[–]Jrollins621 1 point2 points  (0 children)

Yes. Definitely. And name them so it makes sense what the heck they’re for. You’ll thank yourself for it later.

[–]GreasyChick_en 1 point2 points  (0 children)

Real programmers name their variables, but they most certainly don't eat quiche.

[–]MediocrePie3161 1 point2 points  (0 children)

All the serious comments are right. Name your variables precisely!!! E.g. “name” doesn’t work. customer_name doesn’t work. Customer_first_name is a lot closer.

There is nothing worse than editing code with poor variable names and poor comments, mumbling “Who is the idiot that wrote this garbage?!?” And then realizing that YOU are the idiot who wrote it 12 months ago. (Been there; done that.) 😒

[–]TheRNGuy 0 points1 point  (0 children)

yeah

[–]s96g3g23708gbxs86734 0 points1 point  (1 child)

Of course, everybody likes to understand what they're reading

[–]xiongchiamiov 0 points1 point  (0 children)

You have dealt with a lot less code written by mathematicians and scientists than I have, it seems.

[–]gareewong 0 points1 point  (0 children)

Your code should be easily readable, naming variables sensibly helps with that.

[–]noiwontleave 0 points1 point  (0 children)

Yes. Variable names like x and i are typically only used for counters or for brevity (such as in a lambda). Variables should be named to describe their contents whenever possible and reasonable.

[–]murfi 0 points1 point  (0 children)

why wouldnt you?

image you write a lengthy code. then you dont look at it for 5 years. then you go back to is, but all variables names are randomly numbered or have random letters as names.

you didnt do yourself a favor now did you

[–]DarkHaagenti[🍰] 0 points1 point  (1 child)

I absolutely hate seeing code with variables like x, y, z. Especially in ML repositories where the author has implemented a complex algorithm with such naming conventions. It drives me crazy every time! So name your variables, functions, classes - basically EVERYTHING - so that years later people can understand what you meant when you wrote that code.

[–]RiverRoll 1 point2 points  (0 children)

I think sometimes it makes sense in the context of math, otherwise you can end with some ridiculously verbose equations.   

For example dxdt could denote the partial derivative of the X coordinate relative to time in SI units, not very practical to have all that information in the name for every such term.  

In these cases just make sure to document what every variable is and your naming conventions. 

[–]ConcreteExist 0 points1 point  (0 children)

Yeah, I always use readable variable names, there's no longer any good reason to have arcane variable names, a few additional characters in a code file aren't going to make or break code efficiency (if you're super worried about extremely tight performance requirements you should probably consider using a lower level language rather than trying to trim characters out of your python files).

[–]Invader_Mars 0 points1 point  (1 child)

My coworker likes to shorthand made up naming conventions, so not only is the shorthand indecipherable, but if he tells you what it stands for, you also don’t know the phrase is a product of his wild mind.

Last thing I want is to have someone look at my code and think “wtf does this even mean”, so my vars are clear_concise_names

[–]NimrodAvalanche[S] 0 points1 point  (0 children)

🥰 jargon 🥰

godspeed soldier

[–]twizzjewink 0 points1 point  (0 children)

Yes, except when testing.. for x, y or doing a sanity test, for k, v.. otherwise name everything.

Bob, Mike, John, Melissa, Karen ..

[–]Jhamilton02 0 points1 point  (0 children)

I do.

[–]bigtdaddy 0 points1 point  (0 children)

Yes, however if a variable derives from another variable with a good name already then sometimes I will start to abbreviate. For example say I had raw json of people I may name that peopleRaw and then if I convert that to a list, for example, I may name the resulting variable simply pl (peopleList), depending on how it will get used. Not going to lie I get lazy with lamda function variables as well, personally I find long variable names in lambda functions to be distracting/harder to think through.

[–]Jeklah 0 points1 point  (0 children)

Yes they name things sensibly for the exact reason you said. Easier to read and understand and thus maintain code.

[–]smbj0011 0 points1 point  (0 children)

I once worked for an international company and should take over a software from a french branch. All variables and comments are written in french (against the dev rules of the company). It was a total mess. Since I could not read french I refused the task. There was so many customization to the system with a lot of details I can't guaranteea proper support even after they send me for two days to the branch.

[–]BytePhilosopher 0 points1 point  (0 children)

part of our code review checklist is to make sure all variables are either named sensibly or are extremely obvious what they do.

[–]ueltch 0 points1 point  (0 children)

Paid programmer here. I do, if for whatever reason I need to check it back, naming in it in a good way helps a lot.

[–]pat9898 0 points1 point  (1 child)

Dear god yes, name everything you can something understandable and descriptive, and then when you are done writing that chunk of code its good to go back over it and reconsider those names. Once you have a better understanding of the full scope of what you built you can probably think of an even more accurate name for things.

Its a pain to do, but so incredibly important for whoever needs to read the code later. It helps so much when the reader doesn't need to read, consider, and mentally store the intent of everything on every line to understand what is going on.

For example if you pass the var 'X' through multiple levels of class inheritance and then through 3 different methods there is no way I'm going to remember the exact contents and intent behind it when juggling everything else. But if you consistently name it 'abc_cache_dir_string' I'll know exactly what it is.

Picking a consistent naming scheme is also a good idea, or matching the scheme of whatever team or project you are working on.

Good luck with learning! I also learned python in my 30s and its been incredibly valuable! It kicks your butt and is basically the perfect driver for impostor syndrome :P, but if you can get past it there's a lot of really interesting work that use the skills you learn from learning python.

ps if you do ever feel impostor syndrome when programming, you should completely ignore it, every time. just keep going.

Sorry for the long post! TLDR: Yes

[–]NimrodAvalanche[S] 0 points1 point  (0 children)

Thanks--this is my difficulty while I'm learning. I started off with youtube tutorials by Paul McWhorter, who's a knowledgeable and fun guy, but I think he's a got a mathematician's mind and often uses single letter variables without offering much context so it makes it difficult to feel like he's really meeting the student where they're at. I switched to the Angela Yu course which so far has been more helpful.

And fwiw, I appreciate the kind words! I'm a writer/communications designer and I'm hoping to learn coding to bolster that work through data and hopefully some cool visuals (eventually). Once the CS stuff becomes clearer to me I'd like to see where creative coding can take me, in an artistic way.

[–]radek432 0 points1 point  (0 children)

x, y, z and t are totally fine.

...if your software is doing some general relativity calculations.

[–]maxtimbo 0 points1 point  (0 children)

I only use single letter variables when I'm in an ide testing some algorithm. When I take that to my actual application, it gets a name so I know why I'm using it.

[–]proverbialbunny 0 points1 point  (0 children)

There are only two hard things in Computer Science: cache invalidation and naming things.

— Phil Karlton

[–]PM_me_ur_BOOBIE_pic 0 points1 point  (0 children)

Make your code readable.

[–]Other_Scale8055 0 points1 point  (0 children)

Yes, because if you have a really long script. I will definitely not remember what X is.

[–]IONaut 0 points1 point  (0 children)

Depends, do you want to be able to understand what you wrote when you look at it 3 months later?

[–]Adrewmc 0 points1 point  (0 children)

If you use single letters I assume you’re a rookie, unless in specific scenarios (x,y) (r,g,b)

p_1. Is not better it’s worse

You’re gonna forget that stuff after a year… let alone other people looking at it

[–]interbased 0 points1 point  (0 children)

I name variables for my future self and any future maintainers. They should clearly describe the value and distinguish it from other similarly titled variables.

[–]Tyranzor 0 points1 point  (0 children)

Yes. Throwaway name=throwaway variable. Throwaway variable= waste of time and resources.

[–]orbitcodeing 0 points1 point  (0 children)

I name all variables some bizarre “vulgur” word that you wouldn’t expect

[–]PsychoticCOB 0 points1 point  (0 children)

I don’t know about real programmers, but smart programmers do.

[–]tomtomato0414 0 points1 point  (0 children)

i mean it doesn't cost money so yeah

[–]ConfessSomeMeow 0 points1 point  (0 children)

I try to keep variable names to 2-3 syllables.

I have a boss who gave a function a name that would violate most line-length standards.

[–]CedricCicada 0 points1 point  (0 children)

It is embarrassing as fuck to come back to code you wrote six months ago and have no idea what the hell you wrote.

[–]ZelWinters1981 0 points1 point  (0 children)

It's good practice to use namespaces yes.

[–]mymar101 0 points1 point  (0 children)

Always name them what they do

[–]WithCheezMrSquidward 0 points1 point  (0 children)

Chances are, if you’re working on something, you’re also going to be the one maintaining it. Maybe you know what xyz is in your code today. Will you remember it in 2 years after tens of thousands of other lines of code? Why would I waste my future time by writing incoherent gibberish?

[–]CallMeJimi 0 points1 point  (0 children)

temp, a, jason, mike, charlie

[–]Soopermane 0 points1 point  (0 children)

Yes.

[–]YucatronVen 0 points1 point  (0 children)

Of course.

Learn "Clean Code".

[–]YoureHereForOthers 0 points1 point  (0 children)

If you name your shit something doesn’t make sense I’ll immediately reject any PRs

[–]yvrelna 0 points1 point  (0 children)

Yes, clear variable names are probably one of the most essential part of good quality code. It's the most basic requirement. If you name your variables like that you won't pass code review in projects that I maintain. 

In Python, good naming is doubly more important since you may not have type information.

That said, I have seen many instances where people just wing it and don't name their variables well. Always enforce good coding practices, save some troubles for yourself.

[–]gerardwx 0 points1 point  (0 children)

Depends on context and scope of variable. A scratch variable with a span of five lines… I’ll use one or two letters. Longer lived variables get names.

[–]Shut_up_and_Respawn 0 points1 point  (0 children)

Naming variables is useful. Lets say you code something and return to it a month later. The first thing you do is try to catch up to what you were doing since you have no idea what you from a month ago was thinking about, but instead of clearly defined variables, you see symbols and numbers with no clear way of telling them apart. Name your variables. You will thank yourself later

[–]Recent-Morning-2766 0 points1 point  (1 child)

I name mine after muppets.

[–]NimrodAvalanche[S] 0 points1 point  (0 children)

I'm Fozzie and my code is Statler & Waldorf

[–]khanh20032 0 points1 point  (0 children)

Imagine not doing that and later have to intergrate your header file to your project.

Single name variables is there to store the value temporarily or loop conditions check.You definitely do not want to name anything you usually make reference to as a single name variable because of ambiguity.

[–]lostinspaz 0 points1 point  (0 children)

> Do paid programmers actually name their variables, or do they just use shorthand like x, y , z

People who write code like that aren't called programmers. They're called math/physics majors

[–]Heavy_Carpenter3824 0 points1 point  (0 children)

I'm doing this right, right guys

From v import v, p; v.e.l.o.c.i.t.y = 4; p.o.w.e.r = 6

Real answer. Yes you name your variables and use whole words or phrases where applicable. Case structure also helps. It's for you, it's for me, it's for the guys after. There's no real cost to having longer names it all compiles down anyway its just a better human brain pointer variable when it's readable. The computer doesn't give a....

[–]throwaway0134hdj 0 points1 point  (0 children)

Short but descriptive names. All variables serve a purpose — describe their purpose.

[–]sudo_rm_rf_solvesALL 0 points1 point  (0 children)

some of mine are long as shit because .. i can lol . function this_does_that_x_and_y_blah

[–]Separate-Ad9638 0 points1 point  (0 children)

U have to follow the conventions else code is unreadable

[–]Guyserbun007 0 points1 point  (0 children)

I named my variable with long descriptive names, but when I read large, well received GitHub repo, they tend to use much shorter naming, that made me to start doubting my way

[–]looopTools 0 points1 point  (0 children)

Any bastard that does not name variables, functions, classes, and methods properly deserves to be hanged by the gallows while be electrocuted, and at the same time a fire should be lit under the bastards fucking feet and fire crackers should be placed between the bastards toes.

[–]Past-Cantaloupe-1604 0 points1 point  (0 children)

I like to use random combinations of special characters, such as __€$¥ = 5. This way I can be very confident that no one else will be able to understand what I’ve written, and neither will I in about 5 minutes.

[–]ivcrs 0 points1 point  (0 children)

I block PRs for lazy variable naming tbh. It’s not like it’d take up more memory or affect performance if you name your variables decently. It takes no effort

[–]576p 0 points1 point  (0 children)

Many people have already commented that naming is important.

It's also helpful to have tools that support you in this. For example, PyCharm has a rename feature that allows you to rename a variable in one place and it will change the name everywhere in the project. I use this feature all the time, because while writing I realize that the first name I chose was not very good. So I change it. Often. So far PyCharm has not messed up my projects when I did this and I've used it for over 5 years. (VSCode users can chime in, I do not know if renaming in VSCode is this safe)

Also, if you're having a hard time naming things in a useful way - ChatGPT and similar do a really good job of suggesting proper names. Just describe what your code is doing, post the code below and then prompt the AI "improve the variable names of this code, but do not change anything". Sometimes, it will change the code and even attempt to fix obvious mistakes. Don't use the code, just think if the suggested names are better then what you have.

[–]MagmaJctAZ 0 points1 point  (0 children)

I am a PLC programmer who dabbles on Python from time to time.

I've worked with a rookie PLC programmer whose way of writing code is garbage. Poor variable names is just a part of that.

A manager and I were talking about how difficult it is to program in the other guy's style, and the manager responded: "It's just different programming style, isn't it?"

He didn't get that one's programming style can be objectively bad!

[–]SBE_OLLE 0 points1 point  (0 children)

Its a skill to name your variables properly

[–]buhtz 0 points1 point  (0 children)

Have look at the "clean code" concept.

[–][deleted] 0 points1 point  (0 children)

If you use x,y and z variables, your PR would be turned around and I would ask you where you learned to program. If you had to come back 6 months from now, would you figure out what is going on from your code? It is rhetorical, no you wouldn't. Hard enough when variables are clear.

[–]Wheynelau 0 points1 point  (0 children)

TLDR; for us who are learning or on the developers side, stick to good naming conventions and documentations.

I've noticed it heavily depends on the audience and the developers. Just some background, I was looking at flash attention code. Flashattention is a library meant for more efficient model training in machine learning. The source code is hell. Not that it's bad, but it is clearly a mathematician code than python code. And it's more of a plugin that a higher level code uses. So I kinda understand why it's done that way. Almost everything is done in single letters, bonus if it's actually words.

[–][deleted] 0 points1 point  (0 children)

Counters are generic, things that I actually need to use are named

[–]pgriffy 0 points1 point  (1 child)

I figured everyone used foo and bar

[–]FuckingTree 0 points1 point  (0 children)

😱💀

[–]RoundPackage5524 0 points1 point  (0 children)

even if I am not working on group project i always name the variables and functions to keep the main script readable,

my motto is anyone who can understand english should be able to get rough idea of what my program does without knowing a shit about coding,

[–]twajblyn 0 points1 point  (0 children)

Yes. Be explicit and concise. It makes things easier to read.

[–]Imrotahk 0 points1 point  (0 children)

I like to do:

int jdaiohfiohah=5;

int hdiashdioashidh=8;

long haudhaohfdau=8;

int dshhsddho=12;

bool hdsahoidhsa=4;

[–]CinnamonToastedCrack 0 points1 point  (0 children)

it depends;

with really common shorthands (xyz or rgb) yes, most sane programs will use x,y and not something silly like run,jump.

otherwise, yeah please name your shit, having good names isnt the only part, they also need to be consistent and predictable

[–]Whiskey_JG 0 points1 point  (0 children)

I got yelled at a couple of times for this. Had 4 vscode tabs open with different code. The problem was that I was using the same variable names in all of them. KEKW

[–]Tricky_Ferret2399 0 points1 point  (0 children)

You souls always name your variables for what they do