Programming principles and design · Lesson 36 of 60 · Concept lesson · Optional
DRY, KISS, YAGNI
DRY means don't repeat yourself, so each piece of knowledge lives in one place.
KISS means keep it simple, because the simplest solution that works is the easiest to understand and fix.
YAGNI means you aren't going to need it, so don't build features before you need them.
Picture it
Code example
const TAX_RATE = 0.1;
function withTax(price) {
return price + price * TAX_RATE;
}
console.log(withTax(10), withTax(20));Output: 11 22
The tax rate lives in one place. Change it once, and every price follows.
TAX_RATE = 0.1
def with_tax(price):
return price + price * TAX_RATE
print(with_tax(10), with_tax(20))Output: 11.0 22.0
The tax rate lives in one place. Change it once, and every price follows.
Check yourself
Pick an answer for each question. You can retry as many times as you like.
Loading the questions…