Skip to content

Naming Rules

Ori Roth edited this page Apr 2, 2017 · 5 revisions

Naming Rules

This page will describe possible naming-rules for variables :

  • $ -> ret
  • ¢ -> var
  • A variable that counts loop iterations -> counter
  • A variable that sums values inside a loop iteration -> sum
  • A boolean variable wich later in the code will be a condition for an if statement -> cond
  • A static final variable (a constant) -> upperCase & separate words by _ instead of camelCase
  • A temp variable (We can try recognize it by finding variables that represent steps in arithmetic operations for example) will be called temp1, temp2 ... (Or we can do even better with the variables types)
  • List/Array/HashTable/ect. of non primitive types (or even to primitive in specific cases) will get a meaningful names combined with the type of it, for example : operandsList , idToStudentsMap , citiesArray
  • A variable contains the first/last element of a dataType might get an appropriate name : firstActivity , lastAstNode
  • The variable of EnhancedForStatement can be called according to the type we iterate :
    for(City city:Cities){}

Note:

All the naming rules I offered above assume only a plain code is given and a basic analysis of it, but maybe we can take it even further while analyzing the programmer's comments, or even try to mock the thinking process when we give a name to a variable by using an automata which will represent it.

Clone this wiki locally