Gaspard POINTEAU
@Gaspard_PO
un petit excercices de code
un échauffement, une étude, un petit entrainement
prendre le temps, sans la pression du résultat
Lieu où l'on étudie la voie du code
Un gros coding Dojo
d'une journée complète
dans le monde entier
45 minutes,
et ...
Quel est le test à écrire pour faire la plus petite étape ?
Commencer par fail : tester le test
Quel est la plus petite étape à faire pour faire passer le test ?
On nettoie
On fait apparaître des concepts métiers
l'objectif n'est pas les tests, c'est le design !
le batterie de tests n'est qu'un effet de bord en cadeau
oblige à réfléchir à ce que je veux en sortie
ce dont j'ai besoin en entrée
avant de faire la prod
Kent Beck
Les autres outils sont des indicateurs, mais en aucun cas des mesures fiables, et encore moins des objectifs.
C'est un emprunt qu'il faudra rembourser, avec des intérets.
Valide pour certains projets "one shot" :
un petit script pour trier un tas de données, un spike pour essayer une techno ...
Mais la plupart du temps les one-shots sont maintenus pendant des années.
Robert C. Martin aka Uncle Bob
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."
Martin Fowler
"Mal nommer les choses, c'est ajouter au malheur du monde !"
Albert Camus
"There are only two hard things in Computer Science:
- cache invalidation,
- naming things" Phil Karlton
public List<int[]> getFlg() {
List<int[]> list1 = new ArrayList<int[]>();
for (int[] x : theList ) {
if (x[0] == 4)
list1.add(x);
}
return list1;
}
public List<Cell> getFlaggedCells() {
List<Cell> flaggedCells = new ArrayList<Cell>();
for (Cell cell : gameBoard ) {
if (cell.isFlagged())
flaggedCells.add(cell);
}
return flaggedCells;
}
public RGBColor readCurrentColor(BlinkLed led) {
device.sendCommand(new ReadColorRequest(led));
byte[] response = device.readResponse();
int red = response[2] >= 0 ? response[2] : response[2] + 256;
int green = response[3] >= 0 ? response[3] : response[3] + 256;
int blue = response[4] >= 0 ? response[4] : response[4] + 256;
return new RGBColor(red, green, blue);
}
public RGBColor readCurrentColor(BlinkLed led) {
device.sendCommand(new ReadColorRequest(led));
byte[] response = device.readResponse();
return extractColor(response);
}
private RGBColor extractColor(byte[] response) {
int red = convertToPositiveInt(response[2]);
int green = convertToPositiveInt(response[3]);
int blue = convertToPositiveInt(response[4]);
return new RGBColor(red, green, blue);
}
private int convertToPositiveInt(byte byt) {
return byt >= 0 ? byt : byt + 256;
}
/*
* A comment to please checkstyle
*/
/*
* Set the port
*
* @params port
*/
public void setPort(Port port) {this.port=port}
...
} /* end for */
dao.flush();
default :
break;
} /* end switch */
} /* end if */
} /* end if */
} catch ...
Exceptions:
Pas bien !
a.getB().getC().doThings();
Bien !
a.doThings();
Pas bien !
public class Client {
private Service service;
public Client() {
this.service = new ServiceLieAUneDatabasePrecise();
}
public String greet() {
return "Hello " + service.getName();
}
}
Bien !
public class Client {
private Service service;
public Client(Service service) {
this.service = service;
}
...
}
Des frameworks permettent de faire "facilement" de l'injection de dépendances.
A voir si la complexité et les contraintes qu'ils apportent sont compensés.
Ne jamais coupler avec des librairies externes !
Jamais
Toujours utiliser des abstractions et des façades
A class should have one and only one reason to change, meaning that a class should have only one job.
Evitez les Managers
Un manager fait un peu de tout mais mal, beaucoup de rien et embrouille tout le monde.
Objects or entities should be open for extension, but closed for modification.
Penser héritage
Let q(x) be a property provable about objects of x of type T. Then q(y) should be provable for objects y of type S where S is a subtype of T.
objects in a program should be replaceable with instances of their subtypes without altering the correctness of that program.
A client should never be forced to implement an interface that it doesn't use or clients shouldn't be forced to depend on methods they do not use.
one should "depend upon abstractions, [not] concretions."
A. High level modules should not depend upon low level modules. Both should depend upon abstractions.
B. Abstractions should not depend upon details. Details should depend upon abstractions.
Bonus:
You work for a theater, and you're working on a suggestion system for seat allocations. During the process of buying tickets, the customer is offered the best seats available in a given price range. They will be shown a diagram of the theater with all the available seats shown, and the suggested seats highlighted. The customer will be able to change to different seats if they wish. You do not need to write the code to display the theater layout with the suggested seats highlighted. You just have to write the code that decides which seats to suggest.
D'après Emily Bache