Introduction
Names are everywhere in software.
(p 49)
Use Intention-Revealing Names
It is easy to say that names should reveal intent
The name of a variable, function, or class, should answer all the big questions.
bad code:
public List
List
for (int[] x : theList)
if (x[0] == 4)
list1.add(x);
return list1;
}
good code:
public List
List
for (int[] cell : gameBoard)
if (cell[STATUS_VALUE] == FLAGGED)
flaggedCells.add(cell);
return flaggedCells;
}
even better code:
public List
List
for (Cell cell : gameBoard)
if (cell.isFlagged())
flaggedCells.add(cell);
return flaggedCells;
}
Avoid Disinformation
(p50)
Programmers must avoid leaving false clues that obscure the meaning of code.
(p51)
No comments:
Post a Comment