
Locality of Behaviour
Locality of Behaviour is a great principle that should help with maintaining the code. This is the characteristic of the code that enables a developer to only read a small portion of code to understand its function. Without the need to skip, skim, read, jump all over multiple files.
I love that rule cause it DOES MAKE SENSE. I can see many places where we would benefit from it but not always do it that way because of the 'standard’. Which, in the end, nobody knows what it is anymore cause everyone is mixing patterns, antipatterns and the number one performance metric is how fast you can deliver… maybe i rant a bit…
Locality of Behaviour principle :
The behaviour of a unit of code should be as obvious as possible by looking only at that unit of code
Against clean code ?
Does it stand against clean code ? Against dry, separate of concerns and more ? Some will say yes ! Why the rule by uncle Bob about 4-6 lines of methods ? I don`t know yet. Uncle Bob does say that code should be as close to one another as possible but they making a lot of functions can be misleading, then there is argument that if it is, You named them wrongly. We can argue all day.
USE COMMON SENSE.
I have seen code that uses different interfaces, services and overdeveloped 'patterns’ where there should be a single simple service that does what it is meant to do. Cause in the end you can say YAGNI and we all like sphagetti, everything is there, the noodles, the sauce easily available.
In my opinion the MOST IMPORTANT part is the maintenance of the code.
Read more : https://htmx.org/essays/locality-of-behaviour/

