Human-centric code...
...uses human-centric vocabulary
...exists in human-sized units
...clearly expresses dependencies between elements
...is declarative
Human centric vocabulary
Human-sized units
Explicit dependencies
public void DoAThing() {
var thingToDo = new Thing(otherGlobalThing);
// You didn't tell me you needed a thing, and // where did this global come from?
Do(thingToDo);
}
public DoneThing DoAThing(Thing thingToDo) {
return Do(thingToDo);
}
Declarative Code vs Imperative Code
Imperative recipe (How)
1) Place plate on counter top
2) Place slice of bread on plate
3) Spread peanut butter on bread
4) Spread jelly on bread
5) Place another bread slice on top
Declarative recipe (What)
A peanut butter and jelly sandwich IS a thin layer of peanut butter and a thin layer of jelly between two slices of bread
Programming errors are much more likely to arise from misunderstanding intent than from misunderstanding syntax
Code to communicate intent