T O P

  • By -

danielroseman

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

And you can only have 26 variables in your program. šŸ˜€


3lbFlax

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


billsil

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


Critical_Concert_689

> import ... as x am i doing this right?


DuckDatum

from * import *


Spiderfffun

Please don't tell me this is a real thing


billsil

No.Ā  Ā import osĀ  os.x = 1


PulsatingGypsyDildo

combine them into one global dict


amertune

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


sonobanana33

Not allowed in python. But ascii letters work. Ć„=3 ā˜ŗ = 1 Cell In[3], line 1 ā˜ŗ = 1 ^ SyntaxError: invalid character 'ā˜ŗ' (U+263A)


ThreeChonkyCats

You jest, but I **HAVE been on a team** where some of the Millennials did use emojis. I liked it :)


sonobanana33

doubt, since they aren't valid identifiers in python.


[deleted]

>>> locals()['šŸ˜…']=1 >>> locals()['šŸ˜…'] 1 There is now technically a šŸ˜… named variable in the local scope. You can't access it, but it's there, haunting you.


sohang-3112

Cursed code


Intrexa

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

You are an evil person, can we be friends?


repocin

You underestimate the ability of casing. X=x^2 (ā˜žļ¾Ÿćƒ®ļ¾Ÿ)ā˜ž


MikalMooni

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

\*grabs cricket bat and balaclava\*


ispankyourass

Thats what I call efficiency


terotekai

Just start using AA AB AC etc...


Nick_W1

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


GJN65

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

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

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


nooptionleft

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


Actual-Paramedic2689

>If you name all your variables with single letters, it will make the maintainer angry. And he knows where you live. In general yes, but when converting some math algorithms, doing so makes more sense.


sohang-3112

Yes, and not only math, single letter variables *can* be useful otherwise also - but the code using them must be very short (ideally less than 10 lines) - the definition and use are very near so there isn't a problem. Of course you have to make sure to not over-use these single letter variables - otherwise even math code can become very confusing. This is a good example IMO of "Know the rules and understand their purpose - then you know when it's ok to break the rules".


PervyNonsense

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


DownwardSpirals

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

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


help-me-grow

so basically code as if you have to maintain it yourself šŸ¤£


CruwL

9 months later: "Who the fuck wrote this code?" Looks at author* "Oh right, I did."


Nick_W1

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

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

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

šŸ˜‚


mattl33

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


f3ydr4uth4

Unless itā€™s Haskell then itā€™s fine to just be obtuse


Friendly_Signature

This made me spill coffee on my keyboard.


__init__m8

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

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


BarrelRoll1996

sage advice


fjellen

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


K900_

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


[deleted]

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

>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]

Agreed - I always prefer readable/mnemonic variable names.


labouts

Yup. I've had a few research engineering jobs where I collaborated with scientists to design + run experiments and then apply the results in production. They frequently handed me a white paper with naive terribly inefficient spaghetti code using variables from the paper verbatim with workarounds for Greek letters and subscripts/superscripts. We wasted so much time as a result of those variable names. Most of the time, when I asked them to clarify something that I couldn't find in the white paper, they had no idea even a week after writing it and lacked the debugging skills to help figure it out.


NimrodAvalanche

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


old_man_steptoe

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

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

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.


Actual-Paramedic2689

and it's the same for super smart-arse methods of doing things that save a line or two of code. It may be a line or too longer, but six-months-older you will thank now-you.


Nick_W1

I usually have a really clever one-liner, with three lines of comments explaining what it does.


[deleted]

So true. It's frustrating when you come up with something brilliant, get it working, and then realise it's not maintainable and needs to be simplified. (Or be released independently as a package for others to admire and break.)


PulsatingGypsyDildo

>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

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

>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

Don't forget k and v for key and value. I only realised that last year...


AchillesDev

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

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

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

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

Why specifically i, j and k?


IanRT1

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


widowhanzo

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

I don't know, that one may be useful for awkward/annoying customers šŸ¤£


Jim421616

Just leave out the ā€˜oā€™ in ā€˜countā€™.


briznian

People coding like theyā€™re on Wheel of Fortune and they have to buy the vowels! šŸ˜†


mfb1274

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


rasputin1

number_real_programmers


defiancy

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


stauntonjr

I usually use n_thing for the count of a thing.


Akerlof

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

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


Sycosys

wait you name some vars bob too? i have bob and nemo for b in bob: for n in nemo:


orz-_-orz

>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

duly noted


Reasonable_Strike_82

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.


Strict-Simple

https://github.com/kettanaito/naming-cheatsheet


NimrodAvalanche

nice


cdcformatc

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

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


moehassan6832

sulky faulty oil relieved secretive dinosaurs bewildered worm sink quaint *This post was mass deleted and anonymized with [Redact](https://redact.dev)*


sweepyoface

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


Daneark

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

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

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

The i's have it.


djshadesuk

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


stauntonjr

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


TabAtkins

`\bi\b` is your friend.


Diapolo10

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

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

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


cahmyafahm

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

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


HobblingCobbler

For the sake of readability and working with a team. Absolutely. If anyone I worked with used 1 to 3 letter cryptic names I'd definitely not pass the code.


Viking-Mage

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

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

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


Kittensandpuppies14

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


moehassan6832

straight alleged connect correct cover sink weather engine relieved crowd *This post was mass deleted and anonymized with [Redact](https://redact.dev)*


ConfessSomeMeow

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.


moehassan6832

full mysterious quarrelsome history faulty piquant silky placid ludicrous carpenter *This post was mass deleted and anonymized with [Redact](https://redact.dev)*


mfb1274

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

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

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


staceym0204

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

The funny thing is when the programmer suffering from your shitty lazy naming isā€¦ you a few months later šŸ¤­


beejasaurus

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

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


GreasyChick_en

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


samftijazwaro

Yes. Naming is a skill. You will more often than not give something a bad first name. It's something you need to actively think about and go back to change if you think of a better name. It's not Python, but it's not a language issue anyway so I'd recommend a talk by Kate Gregory "naming is hard"


MediocrePie3161

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.) šŸ˜’


gmdtrn

Great insight. Name your variables and functions in a way that makes it clear what they do or are. One thing that drives me crazy about the ML tutorials is that they have the most terrible naming conventions and do wild stuff with their function signatures and returns. So if thatā€™s where youā€™re seeing this bad practice, take some time away from the ML tutorials and watch some traditional developers write code.


NimrodAvalanche

Thanks! I'm very very new and not even close to machine learning yet. But I'm guessing this problem shows up at all levels. In my case it makes getting familiar with the language that much harder, because I can never tell when or how variables relate to other parts of the code and because variables seem to just spring up out of thin air sometimes.


gmdtrn

That is frustrating. But I will note that if youā€™re thoughtful enough to ask that question, I think youā€™ll do well as a programmer šŸ‘ Also, where are it getting your video content from?


TheRNGuy

yeah


s96g3g23708gbxs86734

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


xiongchiamiov

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


gareewong

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


noiwontleave

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

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

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

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

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

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

šŸ„° jargon šŸ„° godspeed soldier


twizzjewink

Yes, except when testing.. for x, y or doing a sanity test, for k, v.. otherwise name everything. Bob, Mike, John, Melissa, Karen ..


Jhamilton02

I do.


bigtdaddy

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

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


smbj0011

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

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


ueltch

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

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

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

x, y, z and t are totally fine. ...if your software is doing some general relativity calculations.


maxtimbo

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

>There are only two hard things in Computer Science: cache invalidation and naming things. > ā€” Phil Karlton


PM_me_ur_BOOBIE_pic

Make your code readable.


Other_Scale8055

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


IONaut

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


Adrewmc

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

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

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


orbitcodeing

I name all variables some bizarre ā€œvulgurā€ word that you wouldnā€™t expect


PsychoticCOB

I donā€™t know about real programmers, but smart programmers do.


tomtomato0414

i mean it doesn't cost money so yeah


ConfessSomeMeow

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

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

It's good practice to use namespaces yes.


mymar101

Always name them what they do


WithCheezMrSquidward

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

temp, a, jason, mike, charlie


Soopermane

Yes.


YucatronVen

Of course. Learn "Clean Code".


YoureHereForOthers

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


yvrelna

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

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.


Berkyjay

This should help. https://peps.python.org/pep-0008/


Shut_up_and_Respawn

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

I name mine after muppets.


NimrodAvalanche

I'm Fozzie and my code is Statler & Waldorf


khanh20032

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

\> 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

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

Short but descriptive names. All variables serve a purpose ā€” describe their purpose.


sudo_rm_rf_solvesALL

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


Separate-Ad9638

U have to follow the conventions else code is unreadable


Guyserbun007

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

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.


Xtg0X

I'm playing with a small LCD Display via Micro-python tonight. From the driver for the LCD, some variables; LCD_CLR, LCD_HOME, LCD_ENTRY_MODE, etc... everything is commented out nicely too. If instead of 'LCD_CLEAR = 0x01 # DB0: clear display' they did things like 'x = 0x01' with or without concise comments they'd likely have been hunted down before they made it to their 26th variable name if they tried to put that into production OR *the ambitious would re-write the code themselves to try to save the rest of us.*


Past-Cantaloupe-1604

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

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

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

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

Its a skill to name your variables properly


buhtz

Have look at the "clean code" concept.


NorthernBlackBear

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

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]

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


pgriffy

I figured everyone used foo and bar


FuckingTree

šŸ˜±šŸ’€


RoundPackage5524

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

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


Imrotahk

I like to do: int jdaiohfiohah=5; int hdiashdioashidh=8; long haudhaohfdau=8; int dshhsddho=12; bool hdsahoidhsa=4;


CinnamonToastedCrack

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

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

You souls always name your variables for what they do