Languages/All/IdentifierNames

From UIT
(Difference between revisions)
Jump to: navigation, search
(Identifiers)
 
(One intermediate revision by one user not shown)
Line 2: Line 2:
 
{{TOC right}}
 
{{TOC right}}
 
== Identifiers ==
 
== Identifiers ==
''Identifier complexity SHOULD be inversely proportional to it scope size'', unknown author (
+
 
If someone can find the original phrase and author, I just remember having seen it on a Linux related mailing list.)
+
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

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