/** *c00kiemon5ter 2015-9-20 add SquareState * c00kiemon5ter 2015-10-1 change the symbol */ public enum SquareState { BLACK('●'), WHITE('○'),
PSSBL('.'), EMPTY(' ');
private final char symbol; SquareState(char symbol) {
this.symbol = symbol; }
public char symbol() {
return this.symbol; } }
正例:
public enum SquareState { BLACK('●'), WHITE('○'), PSSBL('.'), EMPTY(' ');
private final char symbol; SquareState(char symbol) {
this.symbol = symbol; }
public char symbol() {
return this.symbol; } }
$git commit -m "change BLACK symbol from x to ●, WHITE from ○ to O"
/** * @author c00kiemon5ter */ public enum Player { BLACK(SquareState.BLACK), WHITE(SquareState.WHITE);
private SquareState color;
private Player(SquareState color) {
this.color = color; }
public Player opponent() {
return this == BLACK ? WHITE : BLACK; }
public SquareState color() {
return color; } }
正例:
public enum Player { BLACK(SquareState.BLACK), WHITE(SquareState.WHITE);
private SquareState color;
private Player(SquareState color) {
this.color = color; }
public Player opponent() {
return this == BLACK ? WHITE : BLACK; }
public SquareState color() {
return color; } }
public Point evalMove() { AbstractSearcher searcher; Evaluation evalfunc; searcher = new NegaMax();
evalfunc = new ScoreDiffEval();
return searcher.simpleSearch(board, player, depth, evalfunc).getPoint(); }
正例:
public Point evalMove() { AbstractSearcher searcher; Evaluation evalfunc; searcher = new NegaMax(); evalfunc = new ScoreDiffEval();
return searcher.simpleSearch(board, player, depth, evalfunc).getPoint(); }
WORD32 GetCharge(T_Customer* tCustomer) { ... }
正例:
WORD32 GetTotalRentalCharge(Customer* customer) { ... }
public static Set<Point> explore(final Board board, final SquareState state) { Set<Point> possibleMoves = new HashSet<Point>(); Set<Point> statePoints = board.getSquares(state);
for (Point seed : statePoints) {
for (Direction direction : Direction.values()) {
if (shouldSearch(board, seed, direction)) { Point nextPoint = direction.next(seed); nextPoint = direction.next(nextPoint);
while (pointIsValid(nextPoint)) {
if (board.getSquareState(nextPoint) == state) { break; } else if (board.getSquareState(nextPoint) == SquareState.EMPTY) { possibleMoves.add(nextPoint); break; } nextPoint = direction.next(nextPoint); } } } } return possibleMoves; }
public synchronized void waitForClose(final long timeoutMillis) throws Exception {
if(!closed) { wait(timeoutMillis); if(!closed) throw new Exception("MockResponseSender could not be closed"); }}
正例:
public synchronized void waitForClose(final long timeoutMillis) throws Exception { if(!closed) { wait(timeoutMillis);
if(!closed)
throw new Exception("MockResponseSender could not be closed"); }}
class GTEST_API_ AssertionResult {
public: AssertionResult(const AssertionResult& other);
explicit AssertionResult(bool success) : success_(success) {}
operator bool() const { return success_; } private:
bool success_; };
正例:
class GTEST_API_ AssertionResult {
public: AssertionResult(const AssertionResult& other);
explicit AssertionResult(bool success) : success_(success) {}
operator bool() const { return success_; }
private:
bool success_; };
請繼續閱讀「clean code style(2)」