Escolar Documentos
Profissional Documentos
Cultura Documentos
27-Apr-19
A first approach
I want to create a large number of tic-tac-toe partial
games for testing purposes
I could do it this way:
char[][] array;
array = new char[][] { { 'X', ' ', 'O' },
{ ' ', 'X', ' ' },
{ 'O', ' ', 'O' } };
Also...
While our main goal should be to write programs that
are easy to read, it isn’t our only goal
The best thing to do with hard-to-read methods is to
rewrite them
Second best is to explain them in comments
I didn’t include the comments on the slide, but they are in
my code!
Refactoring
Refactoring is reorganizing a program without changing
what it does
Refactor in order to:
Make a program easier to understand
Make a program easier to modify
Before refactoring
public final void testMakeCornerMove() {
setBoard(" oxoxxoxo");
computerPlayer.makeMove(board);
assertBoardIs("xoxoxxoxo");
setBoard("oo xxooxx");
computerPlayer.makeMove(board);
assertBoardIs("ooxxxooxx");
setBoard("oxoxxoxo ");
computerPlayer.makeMove(board);
assertBoardIs("oxoxxoxox");
}