Languages/All/IdentifierNames
From UIT
(Difference between revisions)
(→Identifiers) |
|||
(One intermediate revision by one user not shown) | |||
Line 2: | Line 2: | ||
{{TOC right}} | {{TOC right}} | ||
== Identifiers == | == Identifiers == | ||
− | '' | + | |
− | + | Here are some tips for choosing good identifiers. | |
+ | |||
+ | {{WarningBox|content='''... the length of a variable's name SHOULD be proportional to the size of its scope, and the complexity of its use.''' | ||
+ | * [https://goo.gl/cI631a Andrew Hilton, Anne Bracy; 2015; ''All of Programming - Edition 0''; §13.2.2 Naming]}} | ||
+ | |||
+ | === Example === | ||
+ | <source lang="java"> | ||
+ | // Bad idea : | ||
+ | for (int RidiculouslyLongIdentifierName = 0 ; RidiculouslyLongIdentifierName < 0 ; RidiculouslyLongIdentifierName++) | ||
+ | { | ||
+ | System.out.println(RidiculouslyLongIdentifierName); | ||
+ | } | ||
+ | |||
+ | // Better : | ||
+ | for (int i = 0 ; i < 0 ; i++) | ||
+ | { | ||
+ | System.out.println(i); | ||
+ | } | ||
+ | </source> |
Latest revision as of 12:01, 2 December 2015
|
Identifiers
Here are some tips for choosing good identifiers.
... the length of a variable's name SHOULD be proportional to the size of its scope, and the complexity of its use.
Example
// Bad idea : for (int RidiculouslyLongIdentifierName = 0 ; RidiculouslyLongIdentifierName < 0 ; RidiculouslyLongIdentifierName++) { System.out.println(RidiculouslyLongIdentifierName); } // Better : for (int i = 0 ; i < 0 ; i++) { System.out.println(i); }