Locality of Behavior: A Principle for More Maintainable Code

2025-07-03

This article introduces the principle of Locality of Behavior (LoB), which emphasizes that the behavior of a code unit should be readily apparent within that unit itself. The author uses examples of AJAX requests in htmx and jQuery to illustrate how LoB improves code maintainability. While LoB may conflict with principles like DRY (Don't Repeat Yourself) and SoC (Separation of Concerns), the author argues that judiciously prioritizing LoB enhances code readability and maintainability, ultimately leading to higher software quality and sustainability.

Development design principles