Locality of Behaviour (LoB)
Carson Gross
May 29, 2020
“The primary feature for easy maintenance is locality: Locality is that characteristic of source code that enables a programmer to understand that source by looking at only a small portion of it.” – Richard Gabriel
Locality of Behaviour is the principle that:
The behaviour of a unit of code should be as obvious as possible by looking only at that unit of code
The LoB principle is a simple prescriptive formulation of the quoted statement from Richard Gabriel. In as much as it is possible, and in balance with other concerns, developers should strive to make the behaviour of a code element obvious on inspection.
Consider two different implementations of an AJAX request in HTML, the first in htmx:
< button hx-get = "/clicked" >Click Me button >
and the second in jQuery:
... continue reading