will have less bugs and be easier to read • If you can’t think of a good name, the variable could either be unnecessary, or you may need to think about defining the problem more
beds numOfBeds, numBeds, numberOfBeds nob, x, nobeds Current date current_date cd, date, current, x If a user is active is_active, active?, isUserActive x, active, not_active, active_flag (eh)
your variable does from the name. • Don’t be afraid to use longer names. • Research has shown that code with variable names averaging 10-16 characters took considerably less effort to debug. • You have (or should have) autocomplete on your text editor, you can type it out. • It leads to less typing and debugging / faster development.
all know what the very short variable stands for. • If you’re iterating over a for loop, use ‘i’ and ‘j’. • ‘e’ for event • ‘req’ and ‘res’ for request and response • Look for any naming conventions being used on the project and follow along. Don’t be a cowboy.
values that you’re setting. You may know what it equals now, but you will forget in the future. • You can use the variable across your code. • If you need to change the value in the future, all you have to do it change the variable value. BAD GOOD BAD GOOD
harder • Instead of worrying about naming conflicts, ‘is it no, num, or number?’, etc. You make the decision once early on what to call things. • It frees up space in your head to think about more important things.
variable • Standard abbreviations are alright (stdio, err, etc) • Remove articles (and, or, the, etc) • Consistently only using the first few letters of long words is OK (comp -> computer; jan -> January) • Do not use phonetic equivalents (lite, luv, etc)
few characters • Abbreviate consistently • If you’re having a naming collision, consult a thesaurus • If the project hits a certain size, it is worth it to document naming standards.
name accurately reflects what its naming • Avoid names with similar meanings (ex. num_users and user_num) • Avoid similar names with different meanings (celebName and celebFame in your celebrity tracker) • Avoid homophones (toUsers, twoUsers) • Avoid hard to spell words (hello word!) • Avoid ambiguous characters (I vs l) (also, pick a good font to help with this — I love Inconsolata, the font used in this slide show)