Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

This noncompliant code example has two variables, stem and stern, within the same scope that can be easily confused and accidentally interchanged.:

Code Block
bgColor#ffcccc
int stem; // Position near the front of the boat
/* ... */
int stern; // Position near the back of the boat

...

This compliant solution eliminates the confusion by assigning visually distinct identifiers to the variables.:

Code Block
bgColor#ccccff
int bow; // Position near the front of the boat
/* ... */
int stern; // Position near the back of the boat

...

This noncompliant example prints the result of adding an int and a long value even though it appears that two integers 11111 are being added.:

Code Block
bgColor#FFCCCC
public class Visual {
  public static void main(String[] args) {
    System.out.println(11111 + 1111l);
  }
}

...

This compliant solution uses an uppercase L (long) instead of lowercase l to disambiguate the visual appearance of the second integer. Its behavior is the same as that of the noncompliant code example, but the programmer's intent is clear.:

Code Block
bgColor#ccccff
public class Visual {
  public static void main(String[] args) {
    System.out.println(11111 + 1111L);
  }
}

...