Actions

EmSys

CCoding Style - Use short names for Locals

From EdWiki

Revision as of 09:30, 23 June 2015 by Jshankar (Talk | contribs) (1 revision imported: EdWiki -- Emsys pages from Shukra)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Use short names for Locals

  • Programmers are often encouraged to use long variables names regardless of context. That is a mistake. Clarity is achieved through brevity.
for( theElementIndex = 0; theElementIndex < numberOfElements; theElementIndex++ )
    elementArray[theElementIndex] = theElementIndex;
 
for(  i = 0; i < nelems; i++ )
  elem[i] = i;
  • Short names suffice for local variables; within a function, n may be sufficient, npoints is fine and numberOfPoints is overkill.