Clean Code 01
Clean Code 01
• rođen 1952.
• programer od 1970. (1964.)
• Jedan od autora Manifesto of Agile Software Development
(2001.)
• Clean Code: A Handbook of Agile Software Craftsmanship
(2011.)
• Clean Architecture: A Craftsman's Guide to Software
Structure and Design (2017.)
• Klase (Classes)
• Code Smells
Preuzeto sa : https://www.osnews.com/story/19266/wtfsm/
“I like my code to be elegant and efficient. The logic should be straightforward to make it hard for bugs
to hide, the dependencies minimal to ease maintenance, error handling complete according to an
articulated strategy, and performance close to optimal so as not to tempt people to make the code
messy with unprincipled optimizations. Clean code does one thing well.”*
“Clean code is simple and direct. Clean code reads like well-written prose. Clean code never obscures
the designer’s intent but rather is full of crisp abstractions and straightforward lines of control.”*
“Clean code can be read, and enhanced by a developer other than its original author. It has unit and
acceptance tests. It has meaningful names. It provides one way rather than many ways for doing one
thing. It has minimal dependencies, which are explicitly defined, and provides a clear and minimal API.
Code should be literate since depending on the language, not all necessary information can be
expressed clearly in code alone.”*
“I could list all of the qualities that I notice in clean code, but there is one overarching quality that leads
to all of them. Clean code always looks like it was written by someone who cares. There is nothing
obvious that you can do to make it better. All of those things were thought about by the code’s author,
and if you try to imagine improvements, you’re led back to where you are, sitting in appreciation of the
code someone left for you—code left by someone who cares deeply about the craft.”*
“In recent years I begin, and nearly end, with Beck’s rules of simple code. In priority order, simple
code:
• Runs all the tests;
• Contains no duplication;
• Expresses all the design ideas that are in the system;
• Minimizes the number of entities such as classes, methods, functions, and the like.”*
“You know you are working on clean code when each routine you read turns out to be pretty much
what you expected. You can call it beautiful code when the code also makes it look like the language
was made for the problem.”*
int s;
int s;
int s;
int numberOfStudents;
if(compare(cmd)) {
boolean commandRemove = true;
while(commandRemove) {
executeCommand.peek().unexecute();
unexecuteCommand.push(executeCommand.pop());
Command nextCommand=executeCommand.peek();
if(!compare(nextCommand)) {
commandRemove=false;
}
}
}
if(compare(cmd)) {
boolean commandRemove = true;
while(commandRemove) {
executeCommand.peek().unexecute();
unexecuteCommand.push(executeCommand.pop());
Command nextCommand=executeCommand.peek();
if(!compare(nextCommand)) {
commandRemove=false;
}
}
}
if (commandIsRemove(command)) {
boolean commandRemove = true;
while (commandRemove) {
executeCommand.peek().unexecute();
unexecuteCommand.push(executeCommand.pop());
Command nextCommand = executeCommand.peek();
if(!commandIsRemove(nextCommand)) {
commandRemove = false;
}
}
}
Varijable (Variables) – Nazivi varijabli treba da budu imenice, u slučaju kada se radi o kolekcijama,
treba da budu u množini
unexecuteConsecutiveRemoveCommands(command);
unexecuteConsecutiveRemoveCommands(command);
unexecuteConsecutiveRemoveCommands(command);
unexecuteConsecutiveRemoveCommands(command);
Ukoliko koristite neki od dizajnerskih obrazaca, koristite nazive koji će to jasno staviti do znanja,
kao što je to bio slučaj Remove i RemoveCommand iz prethodnog primera.
• getSelectedProduct();
• getSelectedProducts();
• getSelectedProductDetails();
• getSelectedProductInfo();
• i
• e
• 4
----
• fetchData()
• getUser()
• collectSubmissions()
• retrieveSubscribtions()
• fetchData()
• fetchUser()
• fetchSubmissions()
• fetchSubscribtions()
if (count == 0) {
number = "no";
verb = "are";
pluralModifier = "s";
} else if (count == 1) {
number = "1";
verb = "is";
pluralModifier = "";
} else {
number = Integer.toString(count);
verb = "are";
pluralModifier = "s";
}
U prethodnom primeru pokazano je kako je kod postao čitljivijim dodavanjem metoda koje su mu
dale kontekst.
Navedene su samo neke osnovne preporuke, tokom nastavka često će ponovo biti pominjana
pravila imenovanja.
Pitanja?