forked from isocpp/CppCoreGuidelines
-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
I suggest that a section about duplicated code is added to P.3 "Express Intent".
Duplicated code is a common source of a number of problems. I suggest to just ad a simple example without digging deeper into all issues related to the subject.
Example
Redundant or duplicated code obscures intent and makes it harder to understand the logic. Avoid duplicated code.
void day(bool workday) // Bad, duplicated code.
{
if (workday) {
breakfast();
work();
dinner();
}
else {
breakfast();
readABook();
dinner();
}
}
void day(bool workday) // Good, no duplicated code.
{
breakfast();
if (workday)
work();
else
readABook();
dinner();
}
See suggested solution here: P.3, "Duplicated Code"
Metadata
Metadata
Assignees
Labels
No labels