Download - Código limpio
![Page 1: Código limpio](https://reader035.vdocuments.pub/reader035/viewer/2022081505/554f37d7b4c905471e8b479b/html5/thumbnails/1.jpg)
Clean CodeAnallely Olivares (@tsunllly)
![Page 2: Código limpio](https://reader035.vdocuments.pub/reader035/viewer/2022081505/554f37d7b4c905471e8b479b/html5/thumbnails/2.jpg)
Un día cualquiera ...
Obtener camas bloqueadas* Devuelve una List<Cama>* Params:
● Fecha desde● Fecha hasta● Folio área enfermería ?
![Page 3: Código limpio](https://reader035.vdocuments.pub/reader035/viewer/2022081505/554f37d7b4c905471e8b479b/html5/thumbnails/3.jpg)
![Page 4: Código limpio](https://reader035.vdocuments.pub/reader035/viewer/2022081505/554f37d7b4c905471e8b479b/html5/thumbnails/4.jpg)
Antes/Después
Difícil léctura
○ Scroll a la derecha○ Hay que leer los comentarios○ Muchos posibles flujos
![Page 5: Código limpio](https://reader035.vdocuments.pub/reader035/viewer/2022081505/554f37d7b4c905471e8b479b/html5/thumbnails/5.jpg)
![Page 6: Código limpio](https://reader035.vdocuments.pub/reader035/viewer/2022081505/554f37d7b4c905471e8b479b/html5/thumbnails/6.jpg)
Día a día
Escribimos código
Leemos código !!
buen código / mal código
![Page 7: Código limpio](https://reader035.vdocuments.pub/reader035/viewer/2022081505/554f37d7b4c905471e8b479b/html5/thumbnails/7.jpg)
Buenos nombres
![Page 8: Código limpio](https://reader035.vdocuments.pub/reader035/viewer/2022081505/554f37d7b4c905471e8b479b/html5/thumbnails/8.jpg)
Significativospublic List<int[]> getThem() {
List<int[]> list1 = new ArrayList<int[]>();
for (int[] x : theList)
if (x[0] == 4)
list1.add(x);
return list1;
}
![Page 9: Código limpio](https://reader035.vdocuments.pub/reader035/viewer/2022081505/554f37d7b4c905471e8b479b/html5/thumbnails/9.jpg)
Significativospublic List<int[]> getFlaggedRows() {
List<int[]> flaggedRows = new ArrayList<int[]>();
for (int[] row : gameBoard)
if (row[STATUS_VALUE] == FLAGGED)
flaggedRows.add(cell);
return flaggedRows;
}
![Page 10: Código limpio](https://reader035.vdocuments.pub/reader035/viewer/2022081505/554f37d7b4c905471e8b479b/html5/thumbnails/10.jpg)
Algunos nombres
genymdhms - Impronunciable
i, j - No encontrable
badgesList - Amarrado a un tipo
getActor / findActor - No coherencia
![Page 11: Código limpio](https://reader035.vdocuments.pub/reader035/viewer/2022081505/554f37d7b4c905471e8b479b/html5/thumbnails/11.jpg)
Recomendaciones
Verbo + Sustantivos registerUser getMax countWordsComo preguntas isValidPassword Declarativos markAsInactiveUser
![Page 12: Código limpio](https://reader035.vdocuments.pub/reader035/viewer/2022081505/554f37d7b4c905471e8b479b/html5/thumbnails/12.jpg)
Funciones
![Page 13: Código limpio](https://reader035.vdocuments.pub/reader035/viewer/2022081505/554f37d7b4c905471e8b479b/html5/thumbnails/13.jpg)
Una sola cosa bien hecha
● Facilita pruebas● Facilita reusar código
EsBloqueoDeCama
EstaDentroDeLasFechas
EsDelAreaRequerida
CrearCama
![Page 14: Código limpio](https://reader035.vdocuments.pub/reader035/viewer/2022081505/554f37d7b4c905471e8b479b/html5/thumbnails/14.jpg)
Funciones honestas
Sin efectos secundarios
![Page 15: Código limpio](https://reader035.vdocuments.pub/reader035/viewer/2022081505/554f37d7b4c905471e8b479b/html5/thumbnails/15.jpg)
Funciones pequeñas
![Page 16: Código limpio](https://reader035.vdocuments.pub/reader035/viewer/2022081505/554f37d7b4c905471e8b479b/html5/thumbnails/16.jpg)
Niveles de abstracción
● EsMenorEdad(User u)
● DiasTranscurridosDesde(Fecha fecha)
● DateTime, Now, millis, days, (-)
![Page 17: Código limpio](https://reader035.vdocuments.pub/reader035/viewer/2022081505/554f37d7b4c905471e8b479b/html5/thumbnails/17.jpg)
Leer de arriba a abajo
![Page 18: Código limpio](https://reader035.vdocuments.pub/reader035/viewer/2022081505/554f37d7b4c905471e8b479b/html5/thumbnails/18.jpg)
Argumentos
Ningún argumento :)
![Page 19: Código limpio](https://reader035.vdocuments.pub/reader035/viewer/2022081505/554f37d7b4c905471e8b479b/html5/thumbnails/19.jpg)
Argumentos
Flag
render(boolean isSuite)
* renderForSuite()
* renderForSingleTest()
![Page 20: Código limpio](https://reader035.vdocuments.pub/reader035/viewer/2022081505/554f37d7b4c905471e8b479b/html5/thumbnails/20.jpg)
Principio DRY
Don’t Repeat Yourself
DUPLICATION may be the root of all evil in software
![Page 21: Código limpio](https://reader035.vdocuments.pub/reader035/viewer/2022081505/554f37d7b4c905471e8b479b/html5/thumbnails/21.jpg)
Cometarios
Explain yourself in code
![Page 22: Código limpio](https://reader035.vdocuments.pub/reader035/viewer/2022081505/554f37d7b4c905471e8b479b/html5/thumbnails/22.jpg)
Sugerencias de formateo
* Las variables deben ser declaradas lo más cerca posible al lugar dónde se usan
![Page 23: Código limpio](https://reader035.vdocuments.pub/reader035/viewer/2022081505/554f37d7b4c905471e8b479b/html5/thumbnails/23.jpg)
Sugerencias de formato
Agrupar por afinidad
● Más cerca mientras más relacionados estén
● Separar con líneas en blanco diferencias en la lógica
![Page 24: Código limpio](https://reader035.vdocuments.pub/reader035/viewer/2022081505/554f37d7b4c905471e8b479b/html5/thumbnails/24.jpg)
Sugerencias de formato
Identación
¿Dejar todo en una sola línea?
El equipo dicta las reglasmetodo{….}
metodo {….}
![Page 25: Código limpio](https://reader035.vdocuments.pub/reader035/viewer/2022081505/554f37d7b4c905471e8b479b/html5/thumbnails/25.jpg)
Pruebas
assert assert assert assert
Pruebas pequeñas
Un assert por prueba
![Page 26: Código limpio](https://reader035.vdocuments.pub/reader035/viewer/2022081505/554f37d7b4c905471e8b479b/html5/thumbnails/26.jpg)
No vivir con las ventanas rotas
![Page 27: Código limpio](https://reader035.vdocuments.pub/reader035/viewer/2022081505/554f37d7b4c905471e8b479b/html5/thumbnails/27.jpg)
Finally