this post was submitted on 09 Sep 2023
1052 points (97.2% liked)
Programmer Humor
32558 readers
523 users here now
Post funny things about programming here! (Or just rant about your favourite programming language.)
Rules:
- Posts must be relevant to programming, programmers, or computer science.
- No NSFW content.
- Jokes must be in good taste. No hate speech, bigotry, etc.
founded 5 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
Does anyone have any good advice on variable naming? Here's some of my rules I try to live by:
utils_FooBar
is
not
in bool names._
g_VARIABLENAME
calc_ImportantValueThatWillDecideTheUsersView
is better thancalc_SumYears
if the variable is more important than the others.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
ord_MyWeight
This might be obvious for custom objects, but I'd still do it like this
p_Person
orper_Person
.Seriously it does make a huge difference
Camel case for local variables
Pascal case for global ones
The name should tell me it's purpose
That's it
Right?! People out here are writing a bible on how to name variables lmao
Yeah I bet they feel so good about having the perfect recipe for naming variables, a recipe only they know or care about