cristiansuarez.dev/about/
@cristian_suarez_dev
cristian suarez sin cortes
@criskrus
cristiansuarez.dev/about/
Maintainable code
Código legible
Fácil de modificar
Cubierto por test
Código para hoy
var TennisGame3 = function (p1N, p2N) { this.p2 = 0; this.p1 = 0; this.p1N = p1N; this.p2N = p2N; }; TennisGame3.prototype.wonPoint = function (pN) { if (pN == 'player1') this.p1 += 1; else this.p2 += 1; };
const TennisGame3 = function (name1, name2) { this.scorePlayer1 = 0; this.scorePlayer2 = 0; this.namePlayer1 = name1; this.namePlayer2 = name2; }; TennisGame3.prototype.wonPoint = function (playerName) { if (playerName === 'player1') { this.scorePlayer1 += 1; } else { this.scorePlayer2 += 1; } };
var TennisGame3 = function (p1N, p2N) { this.p2 = 0; this.p1 = 0; this.p1N = p1N; this.p2N = p2N; }; TennisGame3.prototype.wonPoint = function (pN) { if (pN == 'player1') this.p1 += 1; else this.p2 += 1; };
const TennisGame3 = function (name1, name2) { this.scorePlayer1 = 0; this.scorePlayer2 = 0; this.namePlayer1 = name1; this.namePlayer2 = name2; }; TennisGame3.prototype.wonPoint = function (playerName) { if (playerName === 'player1') { this.scorePlayer1 += 1; } else { this.scorePlayer2 += 1; } };
Métodos / funciones
Variables
String name; int distanceInMeters; Boolean isNegative; Boolean hasSymbol; public class Customer { /*****/ }
sustantivos
Clases
Paquetes
minúscula
mayúscula
verbos
minúscula
public void saveUser(User user); public int countUsers(List<User> users); public Boolean hasUsers(List<User> users);
public Boolean hasMoreThanMaximumFields(int fields) { if (fields > 10) { return true; } return false; }
NO Magic numbers/words
public Boolean hasMoreThanMaximumFields(int fields) { private int maxFieldsPerRecord = 10; if (fields > maxFieldsPerRecord) { return true; } return false; } // Not meaningful enough // private int numberTen = 10;
public Boolean hasMoreThanMaximumFields(int fields) { if (fields > 10) { return true; } return false; }
NO Magic numbers/words
public Boolean hasMoreThanMaximumFields(int fields) { private int maxFieldsPerRecord = 10; if (fields > maxFieldsPerRecord) { return true; } return false; } // Not meaningful enough // private int numberTen = 10;
List<String> nameList = new ArrayList<>{"Juan", "Noe", "Maria"}; String addressString = "221b, Baker Street";
NO incluir información técnica
List<String> names = new ArrayList<>{"Juan", "Noe", "Maria"}; String address = "221b, Baker Street";
List<String> nameList = new ArrayList<>{"Juan", "Noe", "Maria"}; String addressString = "221b, Baker Street";
NO incluir información técnica
List<String> names = new ArrayList<>{"Juan", "Noe", "Maria"}; String address = "221b, Baker Street";
function check(foo, bar) { if (foo === bar.length) { return true } return false } check(5, 'hello')
List<String> nameList = new ArrayList<>{"Juan", "Noe", "Maria"}; String addressString = "221b, Baker Street";
NO incluir información técnica
List<String> names = new ArrayList<>{"Juan", "Noe", "Maria"}; String address = "221b, Baker Street";
NO nombre genérico + SÍ nombre con sentido
function isWordLengthCorrect(wordLength, word) { if (wordLength === word.length) { return true } return false } isWordLengthCorrect(5, 'hello')
NO usar alias
Customer customer = new Customer("John Smith"); // Different part of the code Customer client = new Customer("Jane Doe");
NO nombres impronunciables
// None of these names provide useful information int d; String n; boolean sg;
// These names clearly state what they represent int distanceInLightYears; String starName; boolean isSupergiant;
Según Kent Beck
Según Carlos Blé
Piensa en tus compañeros
y en tu "yo" del futuro
«Echarle la culpa a las personas de los desastres en el código es como escupir para arriba; no te lo recomiendo»
Carlos Blé
Código sostenible
- Carlos Blé -
Clean Javascript
- Miguel A. Gómez -
Clean Code
- Robert C. Martin -
Código sostenible
- Carlos Blé -
https://codigosostenible.com/
cristiansuarez.dev/about/
@cristian_suarez_dev
cristian suarez sin cortes
@criskrus
cristiansuarez.dev/about/