Sergej Chodarev (sergejx.net)
You will not make the deadline by making the mess. Indeed, the mess will slow you down instantly, and will force you to miss the deadline. The only way to make the deadline—the only way to go fast—is to keep the code as clean as possible at all times.
– Robert C. Martin: Clean Code
Every system is built from a domain-specific language designed by the programmers to describe that system. Functions are the verbs of that language, and classes are the nouns. ‹…› The art of programming is, and has always been, the art of language design.
Master programmers think of systems as stories to be told rather than programs to be written. They use the facilities of their chosen programming language to construct a much richer and more expressive language that can be used to tell that story.
– Robert C. Martin: Clean Code
We would like a source file to be like a newspaper article. The name should be simple but explanatory. The name, by itself, should be sufficient to tell us whether we are in the right module or not. The topmost parts of the source file should provide the high-level concepts and algorithms. Detail should increase as we move downward, until at the end we find the lowest level functions and details in the source file.
– Robert C. Martin: Clean Code
A code smell is a surface indication that usually corresponds to a deeper problem in the system.
i++; /* increment i */
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
def validate_age(value):
validate_type(valie, :integer)
validate_min_integer(value, 0)
def validate_quantity(value):
validate_type(valie, :integer)
validate_min_integer(value, 0)
int m_otCalc() {
return iThsWkd * iThsRte +
(int) round(0.5 * iThsRte * max(0, iThsWkd - 400));
}
int straight_pay() {
return get_tenths_worked() * get_tenth_rate();
}
int overtime_pay() {
int overtime_tenths = max(0, get_tenths_worked() - 400);
int overtime_pay = overtime_bonus(overtime_tenths);
return straight_pay() + overtime_pay;
}
int overtime_bonus(int overtime_tenths) {
double bonus = 0.5 * get_tenth_rate() * overtime_tenths;
return (int) round(bonus);
}
process_data()
function do?Refactoring is a disciplined technique for restructuring an existing body of code, altering its internal structure without changing its external behavior.
Rely only on reliable things. Beware of accidental complexity, and don’t confuse a happy coincidence with a purposeful plan.