| ▲ | teiferer 2 hours ago | |
> They're used exactly once To me, that's key here. That things are scattered over multiple files is a minor issue. Any competent IDE can more or less hide that and smoothen the experience. But if you have factored some code into a function, suddenly other places may call it. You have inadvertently created an API and any change you make needs to double check that other callers either don't exist or have their assumptions not suddenly violated. That's no issue if the code is right therr. No other users, and the API is the direct context of the lines of code right around it. (Yes you can limit visibility to other modules etc but that doesn't fully solve the issue of higher cognitive load.) | ||
| ▲ | exceptione 2 hours ago | parent [-] | |
That is an important consideration which you should weigh against the clarity gained by breaking up your code in units of logic. That is precisely the reason why for a function the scope of its container should be constrained. A class with a Singe Responsibility (SRP) would not suffer from several private methods. Breaking up your methods in a God Class brings both a decrease and an increase of mental load. Also, in functional programming languages one can nest functions, and OOP languages oftentimes can nest classes. Haskell does function hiding the most elegant imo, by means of `where`: | ||