Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
hendrik5238yI usually start off with short, cryptic names because I find it easy to work with in the beginning of a project.
When I start refactoring things I try to make sense of what the variable does (booleans usually get a name like ...Toggle or ...Mode, factors ...Factor, counters ...Counter and so on). In my opinion this makes for great readability conpared to using plain names.
Also, this way, there are no random variables called 'temp' with unknown meanings (tempCounter, tempTokens, tempText etc is a whole lot better than just temp).
Hope this helps a bit... -
gaben2698yAlways go for descriptive over short. Every ide on Earth has auto fill now, there's no excuse for using shorter less readable variables. Only exception is mathematical or physical quantities, ie pi, x, y, dv, etc.
-
boolean shouldVariablesBeLongAndDescriptiveToAvoidConfusionAndUseCamelCase = true;
-
Descriptive over Cryptic but Concise over Illustrative.
Variable should give a *short* description of what they're meant for. Single characters and abbreviations are too short, sentences are too long.
And ask yourself often, do I really need to store something in a variable, or can I use & return values directly and worry only about good *method* names? -
@TangChr Maybe I'm alone in this, but I really dislike the whole foo bar baz fart thing. Examples are so much easier to understand with realistic examples!
-
donuts236728yFunny so I was talking to a smart colleague (that's a compliment where I work) about how all the variable names are in different styles.
i.e. Testcase,testCase, Testcase
Him: yea we have a style doc but no one bothers to read it -
I'd love to read a book about that. Specially about defaults.
I begin using variable like name, address, path, then I need a second name and things begin to mess up: name, nameSecondPerson (just a temp variable), address, Email (yeah, now I have capitals), work_address, dogsName and go on.
At the end i need to use the autocomplete the variables names, I as have no idea anymore. Last, I have to stop and reorganize code, but if course I usually never get to the point to finishes organizing.
Related Rants
In all honesty, if there was a course on giving variables good, informative and not completely stupid names... I would take it.
undefined
variable
naming
fordummies
goodpractice
devkryptonite