Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to name variables

  • What rules do you use to name your variables?
  • Where are single letter vars allowed?
  • How much info do you put in the name?
  • How about for example code?
  • What are your preferred meaningless variable names? (after foo & bar)
  • Why are they spelled "foo" and "bar" rather than FUBAR
like image 655
BCS Avatar asked Oct 15 '08 03:10

BCS


People also ask

How do you give a variable a name?

Rules for naming a variableA variable name can only have letters (both uppercase and lowercase letters), digits and underscore. The first letter of a variable should be either a letter or an underscore. There is no rule on how long a variable name (identifier) can be.

What is a good example of a variable name?

Variable names are shown in green color in the questionnaire Designer. The following are examples of valid variable names: age, gender, x25, age_of_hh_head. The following are examples of invalid variable names: age_ (ends with an underscore);

How do you name variables in statistics?

Most surveys use one of three methods for naming variables: cryptic codes, question numbers (e.g. “1”, “2”, “3” or “A1”, “A2a”, “A2b”) or descriptive names (e.g., “gender”, “age”, “employment”).


2 Answers

function startEditing(){    if (user.canEdit(currentDocument)){       editorControl.setEditMode(true);       setButtonDown(btnStartEditing);    }  } 

Should read like a narrative work.

like image 185
Tony BenBrahim Avatar answered Sep 18 '22 13:09

Tony BenBrahim


One rule I always follow is this: if a variable encodes a value that is in some particular units, then those units have to be part of the variable name. Example:

int postalCodeDistanceMiles; decimal reactorCoreTemperatureKelvin; decimal altitudeMsl; int userExperienceWongBakerPainScale 

I will NOT be responsible for crashing any Mars landers (or the equivalent failure in my boring CRUD business applications).

like image 22
Jeffrey L Whitledge Avatar answered Sep 17 '22 13:09

Jeffrey L Whitledge