Languages/All/IdentifierNames

From UIT
(Difference between revisions)
Jump to: navigation, search
(Identifiers)
 
Line 2: Line 2:
 
{{TOC right}}
 
{{TOC right}}
 
== Identifiers ==
 
== Identifiers ==
// 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);
+
}
+
 
Here are some tips for choosing good identifiers.
 
Here are some tips for choosing good identifiers.
  
''Identifier complexity SHOULD be proportional to it scope size'' -- unknown author
+
{{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]}}
If someone can find the original phrase and author, feel free to point me to the reference, I just remember having seen it on a Linux related mailing list.
+
 
+
  
Example :
+
=== Example ===
 
<source lang="java">
 
<source lang="java">
 
// Bad idea :
 
// Bad idea :

Latest revision as of 13:01, 2 December 2015

Contents

Identifiers

Here are some tips for choosing good identifiers.

Dialog-warning.png

... 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);
}
Personal tools
Namespaces
Variants
Actions
Navigation
Browse
Toolbox