Java Reference
In-Depth Information
guishable from the Greek-character subset of the Mathematical Alphanumeric Symbols
(Unicode Range 1D400-1D7FF).
AvoiddefiningidentifiersthatincludeUnicodecharacterswithoverloadedglyphs.One
straightforward approach is to use only ASCII or Latin-1 characters in identifiers. Note
that the ASCII character set is a subset of Unicode.
Do not use multiple identifiers that vary only by one or more visually similar charac-
ters. Also, make the initial portions of long identifiers distinct to aid recognition.
According to the JLS, §3.10.1, “Integer Literals” [JLS 2013],
An integer literal is of type
long
if it is suffixed with an ASCII letter
L
or
l
(ell);
otherwise, itisoftype
int
.Thesuffix
L
ispreferred because theletter
l
(ell) isoften
hard to distinguish from the digit
1
(one).
Consequently,use
L
,not
l
,toclarifyprogrammerintentwhenindicatingthataninteger
literal is of type
long
.
Integer literals with leading zeros, in actuality, denote octal values not decimal values.
According to §3.10.1, “Integer Literals,” of the JLS [JLS 2013],
An octal numeral consists of an ASCII digit
0
followed by one or more of the ASCII
digits
0
through
7
interspersed with underscores, and can represent a positive, zero,
or negative integer.
This misinterpretation may result in programming errors and is more likely to occur
whiledeclaringmultipleconstantsandtryingtoenhancetheformattingwithzeropadding.
Noncompliant Code Example
This noncompliant code example has two variables,
stem
and
stern
, within the same
scope that can be easily confused and accidentally interchanged:
int stem; // Position near the front of the boat
/* ... */
int stern; // Position near the back of the boat
Compliant Solution
This compliant solution eliminates the confusion by assigning visually distinct identifiers
to the variables: