4 ms·
I completely agree with this. When designing classes it is very easy to get carried away and incrementally add bits to the class instead of passing dependencies
by gpderetta 3y ago
I completely agree with this. When designing classes it is very easy to get carried away and incrementally add bits to the class instead of passing dependencies explicitly.
Arguably even config is too much and generally functions should only take the subset of config.
In the end this is more art than engineering: classes allow encapsulating all state that needs to be used by all functions together; but as you start making exceptions you'll end up with the mess you describe. The art is finding the right balance between what goes in a class and what should be a standalone (possibly generic) function. Personally, I'm still far from mastering that art.
Alexander Stepanov has a lot to say about this.
- vaughan 3y agoThere is definitely an art to it at some point, but I see a lack of tools to be a big problem. We are in the stone-age of programming at the moment. I think the solution is visualization. I want to click on any variable, and see its full data-dependency graph. All the functions it flowed through and all the transformations that occurred all the way back to a single source of truth. With this in hand, I think it would be much easier to understand how to group methods and state. We should write code such that this data-dependency graph is easily understood by humans.