U nd to rembr tht mny snr devs grw up prgrmng on old hrdwr tht ddn't hv mch mmry & oftn th lang ony allwd shrt var nms anywy. Also thy wr th gen of txtspk fr smlr rsns.
Yngr snr devs pckd up bd hbts frm tht gen.
And here's a sentence that's not squashed to cleanse your palettes / give a sigh of relief because I figure if I need a break from typing like that, you need a break from reading it.
I was mostly poking (heh) fun at myself, (also) a member of the generation I spoke about. Very much not a professional, but I do code a little, and know about the non-triviality of naming things.
Also also, for reasons I won't go into, my phone is still a flip phone.
I started coding with TurboBasic which allowed variable names of any length but the compiler only looked at the first two letters (and case-insensitive at that), so DOUGHNUT_COUNT and DoobieCounter were actually the same variable. Good times debugging that kind of shit.
Yeah, I was thinking of old 8-bit computers that did the same ignore-after-second-char thing. Most people didn't bother typing the extra characters though because 1) those characters took up valuable memory and 2) if you accidentally put a keyword in the middle of your longer name, the tokeniser would see it and assume it was a keyword.
e.g. Calling your variable FORGET seemed like a good idea until you got a syntax error because FOR and GET are both keywords. FO it is, then. Or just F.
COLOR was cursed too; OR is usually a keyword, even if COLOR itself isn't. British English COLOUR might save you here, but you're still losing those four extra bytes.
U nd to rembr tht mny snr devs grw up prgrmng on old hrdwr tht ddn't hv mch mmry & oftn th lang ony allwd shrt var nms anywy.
My generation. Many of us learned and adapted over time, and use perfectly decent variable names now.
Also thy wr th gen of txtspk fr smlr rsns.
Nope. Got my first cell phone 8 years into my professional life, and 18-20 years after I started programming. Txtspkrs r th nxt gnrtn. Whippersnappers!
Hey, sometimes we put a little effort into our acronyms. I published a component named UTI and it was too late to change it by the time management caught on.
"Actually we decided we're going to take this project in a completely different direction. Go ahead and rework 90% of what you just created over the last six months."
It was a trivial enough component that upper management couldn't be bothered to give a shit, and middle management was toothless. I left before HR had to get involved again.
Hah, I (a Sr developer at the time) once built an entire mapping layer in our ETL system to deal with the fact that our product had long and expressive names for every data point but our scientists used statistical tools that had no autocomplete and choked on variable names longer than 32 chars so they named everything in like 8 chars of disemvoweled nonsense.
Also, can somebody explain this to sysadmins when it comes to naming computers?
I mean programmers can have some weird naming conventions, but I've never met an adult professional programmer who named all his variables after planets or Harry Potter characters or just called everything stuff like ADMUTIL6 or PBLAB03T1 or PBPCD1602.
Harry Potter characters is a perfectly reasonable server naming scheme. Server names should be easily recognisable but not tied to any particular service/project/function on that machine (as the server may be used for other things later etc)
There was a thread about that on c/selfhosted a few weeks ago. Created by a particular wild-cat-inspired sysadmin, I might add.
But on a more serious note, the interactions between a sysadmin and their servers (that they have enough responsibility for to be able to name) are much more intimate than the interactions between a dev and their variables. The server names also exist in a much larger namespace, so they need to be more unique.
Any one who worked on an Oracle DB when they had the 30 character object name limit learned to make names like this. You'd figure out all your domain objects, and abbreviate them all (person could be PRS_, account could be ACCT_, etc). It was a horrible experience.
I mean, sure, but it's not like that makes you forget the normal English words. Just don't abbreviate those words and you've likely got a semi-decent variable name.
Well, and my expectation for non-shit seniors is to be somewhat good at their job and to lead by example.
Nah, always use as lewd names as possible, like really over the top, preferably r34 compliant. And the comments need to be there to explain the fictional stories behind all the names and all the lewdness - and not really to explain what the code does, that's just a common misconception.
If someones dares to look into my code they need to be ready to suffer.
(And no, I'm not a dev, no one in my team can code anything, boss won't give me a an actual dev - and when I write something for other ppl as a favor I make an effort to make the code clean and comments only mildly amusing)
Reminds me when back in the day I was working on a system where one of major component's acronym was BOOTY. It was hard picking right terms and names for the new parts, but I managed to fit a variable named BOOTY_SLAP in there such that none of the reviewers even questioned it.
Reminds me of a system I worked in that utilized DADDY ports. It was always amusing to overhear conversations about expanding the DADDY ports, things being stuck in DADDY ports, etc. Submitting tickets for them was always a lot of fun.
Does anyone have any good advice on variable naming? Here's some of my rules I try to live by:
camelCase
use prefixes
prefixes should be one word followed by an underscore.
10 character limit or 3 word limit, not counting the prefix
functions should be prefixed with the file in which they're defined, ie utils_FooBar
file names should be one word
Start Bools with is
Don't use not in bool names.
This has farther-reaching implications that will keep you from making confusing code most of the time (I'm sure this will be controversial, but it works no matter what they say)
start output with _
Globals should be g_VARIABLENAME
use the least amount of words possible
but being too verbose can draw attention - use this to aide in readability
calc_ImportantValueThatWillDecideTheUsersView is better than calc_SumYears if the variable is more important than the others.
Even the greatest variable names are not replacements for documentation
Even the most readable code is not replacement for documentation.
Force yourself to love documentation.
Edit: I realize I was speaking about function-naming with the prefix stuff.
For variables, I still use prefixes, but for variable type. Even if you define the variables as types, it's still incredibly useful. For instance,
a string is s_MyName,
enumerable is e_MyType,
A number is int or double or whatever i_MyAge or d_MyWeight
This might be obvious for custom objects, but I'd still do it like this p_Person or per_Person.
Don't code in a language/style that requires you to write code that makes prefixing necessary - divide and conquer instead
Readable code and well written unit/BDD tests is much better than separate documentation that will go out of sync the minute another Dev does some surgical incision into the code
Be verbose if you need to in order to convey the relevant semantics, the characters are virtually free
Use the casing that is mainstream/recommended by its' developers for the language at hand
I have to disagree on some points, but I def feel like you're helping me learn, so for that I am grateful.
I feel like you're speaking from the perspective of a perfect coding environment, which if you have that, that's great. Maybe all your code is in one place, maybe you have an IDE that does a lot of the work for you, and that's great. However, for most of us, that's rarely the case.
Prefixes have been an absolute game changer for me personally, and I will never not use them again.
I have also found that verbosity of variable name and readability are mutually exclusive. A long variable name, most of the time, takes away from the logic. Yes, they are "free" as far as memory, but are very expensive to reliability.
Units tests, again are great, but most places think unit tests are like golden toilets. It sucks, but that's the way it is. Usually you're given a task, and if it's not done next week, maybe you're not as good as they thought.
I might be already exposing myself as an emacs user, but I think Lisp naming convention is pretty reasonable. I use it in other languages as far as their language rules allow me
if a variable or function is a predicate (as in if it tests if something is true or not), append p or _p/-p
variables and functions both have lisp case variable-name-here. Sub for _ in languages that dont allow - in names
unused or unexposed variables are prefixed _ .
top level packages get naming rights. So if I'm making cool-package then variables or functions that are specific to it are cool-package-variable (especially if it is exposed to other packages). cool-package/variable is also good if allowed.
otherwise, separate namespaces with /. So there's main-function and my/main-function. If / is reserved, then I assume the language has a way of segmenting namespaces already and just default to that since _ or - would get ambiguous here.
I have never had any patience with variable names when I realize I have to do a 3-way swap: c=a, a=b, b=c. I'm sure there's 40 years of goddamit=a and fml=a in the wake I've left behind me.
I see this a lot less with developers whose companies actually provide decent IDEs. Especially front end devs or older devs who still use text editors.