lunes, 20 de enero de 2014

What’s clean code for me?

     When I had the interview on Pernix-Solotions, the boss asked if it was good programming, to which I replied: Yes sir! After that, the first book I had to read are here Pernix-Solutions was Clean Code. Now that I finished reading the book, I had a serious error the concept of good programmer.

    A good code is not enough to be functional, it must be understandable. This means that other programmers but do not know the code, you must understand what each method, each function or class structure. You should also be understandable for oneself, it may be months where you do not touch a specific code but when returning again, one must be in the ability to understand well and continue where you left off the last time you worked on code.

     Before joining Pernix, l boss told me to do the game Tic Tac Toe, and makes the game properly served but did not have good programming practices. Looking at the code after some time, there are many errors like this (code).

     Now after reading the book Clean Code. What we can correct for it is simple function?

     Comments that are at the beginning of the function, are useless (Error 1), so the function does not have a meaningful name (Error 2). The function has 18 lines of code should be maximum 5 lines of code (Error 3). What is the meaning of the following variables? 'row', 'column' and 'diagonal' (Error 4). Which means that some of these variables is true? (Error 5). The code must be in English (Error 6) and must follow programming standards (Error 7). Now, if we correct this code should look like:

public boolean isThereAWinner(Board board){
  if(checkRow(board) || checkColumn(board) || checkDiagonal(board))
    return true;
  else
    return false;
}

     When written CLASSES, these should be small and should not have more than 100 lines of code, if you have more than that, the class has too much responsibility, example (code). Here is a class that has more than 500 lines of code. Has giant methods and also which are very difficult to understand. Perfectly is class can be divided in 3 classes of less than 100 lines each, and each would have its own responsibility and not mix.


     This is what it means to me, Clean Code.

No hay comentarios:

Publicar un comentario