6 ms·
Dependency distance is why it is good to have programming language constructs like for (init; test; increment) body-statement and their ilk. Though the
by kazinator 11y ago
Dependency distance is why it is good to have programming language constructs like
for (init; test; increment)
body-statement
and their ilk. Though the evaluation is out of order, (test, body-statement then increment), certain related things are kept together.
It also explains why infix notations (and 2D math notation) are effective: they physically clump semantically near things.
Postfix notations with no parentheses are absolutely the worst; you don't know what goes with what at a glance:
1 2 + 3 4 + 5 6 + * 7 8 / - *
If my eyes land on, say, the inner * , it's not immediately clear what the left operand is.
Prefix with parenthesization lets us fold and indent the darn thing for a 2D visualization:
(* (+ 1 2) (- (* (+ 3 4) (+ 5 6)) (/ 7 8)))
^__ orig. distance__^
The (- ...) expression jumps down and gets indented. Thus it is visually lined up with its sibling, and near the connecting operator:
(* (+ 1 2)
(- (* (+ 3 4) (+ 5 6)) (/ 7 8)))
We recursively apply this:
(* (+ 1 2)
(- (* (+ 3 4)
(+ 5 6))
(/ 7 8)))
(* (+ 1 2)
(- (* <---
... reduced distance, and visual alignment
(/ <---
- jonsen 11y agoPrefix (with fixed number of arguments) need no parentheses * + 1 2 - * + 3 4 + 5 6 / 7 8 Postfix can be indented similarly 1 2 + 3 4 + 5 6 + * 7 8 / - * Or parentheses less infix 1+2 * 3+4 * 5+6 - 7/8