DRY(don’t repeat yourself) - код не должен дублироваться.
KISS(Keep it simple, stupid) - следует избегать ненужной сложности.
YAGNI(You aren't gonna need it) - не создавать то что не требует задача. Не нужно предсказывать будущее, задачи меняются.
Замена if - else if - else структуры на if, для повышение читаемости.
function doSomething() {
if (userActive) {
if (userSubscribed) {
if (isPaidUser) {
doSomething();
} else {
new Error("Not a pro user");
}
} else {
new Error("User not subscribed");
}
} else {
new Error("User not active");
}
}
function doSomething() {
if (!userActive) {
new Error("User not active");
}
if (userSubscribed) {
new Error("User not subscribed");
}
if (isPaidUser) {
new Error("Not a pro user");
}
doSomething();
}