5 ms·
SOLID is just a random arbitrary acronym about some principles that are somewhat obvious. However most people don't fully understand these principles deeply. Wh
by nendroid 6y ago
SOLID is just a random arbitrary acronym about some principles that are somewhat obvious. However most people don't fully understand these principles deeply. What happens is if you are using OOP you are not using SOLID to its full extent. Ironic that SOLID comes from OOP.
Either way SOLID are arbitrary rules of thumb. Grouped together arbitrarily to spell out SOLID and kind of maybe sort of right depending on your opinion.
1. SRP. Gather together the things that change for the same reasons. Separate things that change for different reasons.
I disagree. Unless this thing is talking about namespacing which is more of an aesthetic/psychological thing... You should not organize your program this way where logic of one thing is tied with the logic of another thing. All things should be ungrouped as much as possible.
You should also separate all things that "change" and all things that don't "change" and try to keep the things that "change" as small as possible.
All logical modules in your program should be separated as much as possible at the lowest layer, nothing should be grouped... and higher layers should be compositions of lower layers. But the basis of your program at the lowest layer: everything should be separated and nothing should be grouped.
In other words use combinators as MUCH as possible. OOP's promotion of methods that operate on shared mutable external scope actually prevent you from doing this.
2. A Module should be open for extension but closed for modification.
Agreed. The problem is if your program is OOP your modules are objects which group methods together through shared mutable state. It means that you cannot extend one method without modifying the entire object.
So basically OOP practitioners can never modify an addOne method into addTwo. They can't even add an addTwo method into the object as that constitutes modification. What they can do is inject that entire object into another object. Either do this or use inheritance which OOP says is just bad.
Instead. Use combinators. You have an addOne combinator? Create an addTwo combinator. Recompose your combinators to form the higher level logic you wanted.
3. A program that uses an interface must not be confused by an implementation of that interface.
Yeah I mean sure. Don't have your flatten Function be able to operate on an integer.
4. Keep interfaces small so that users don’t end up depending on things they don’t need.
Agreed the problem is, the definition of an object in OOP usually ties muteable state and logic together. Your average object has a getter and setter which are tied together by external scope, so by definition OOP ties together things that shouldn't belong together. You are not keeping your interfaces small.... by definition it is already too big.
If you defined the logic as I said above separating state changes away from combinators you'd have even smaller interfaces. One for changing state. And the other logic is stateless.
5. Dependency inversion principle.
I mean yeah. Write your logic in layers. The problem is OOP people only use this principle at the module level.
The better way to program is to have all your methods follow the dependency inversion principle. You can't do this if methods are modifying external scope shared by another method. Use combinators and by definition every sector of your program is following this principle not just "modules"
- AlchemistCamp 6y ago> All things should be ungrouped as much as possible. Why?
- lerptime 6y agoBecause you cannot predict the future of your program. Coupled logic that seems correct now may need to be uncoupled in the future. By having every sector of logic be ungrouped it leads to maximum reusability for the future. Technical debt is at the lowest possible level in projects where every piece of logic is uncoupled. In fact the very phenomenon of Technical debt arises from logic that's hard to uncouple. By having every sector of your program be a lego brick you are preparing your program for an inevitable future where the structure must be reconfigured. Grouping logic together is like super gluing lego bricks together because it seems like they belong together. There's a term for this style of coding that's actually negative. It's called ravioli code. But the negativity mostly applies to when this style of coding is used in OOP.
- AnimalMuppet 6y agoVery, very wrong. > In fact the very phenomenon of Technical debt arises from logic that's hard to uncouple. No, one kind of technical debt arises that way. Not the only kind. There's another kind that arises when everything is in such small pieces that nobody can tell how the pieces relate to each other. You can easily understand each piece, but you have to go through a chain of a bazillion function calls to see what's actually going on. > By having every sector of your program be a lego brick you are preparing your program for an inevitable future where the structure must be reconfigured. This is like economists, who have correctly predicted nine of the last two recessions. Sure, you're prepared for when the change comes (if you can find where to make it - see above). You've also prepared for all the changes that never come. That's rather wasteful. > Because you cannot predict the future of your program. Coupled logic that seems correct now may need to be uncoupled in the future. Sure, it may. And when that happens, we'll decouple it. And in the meantime, we'll enjoy the coupling that, at the moment, is the correct thing. See, this is all in the context of SOLID, the very first piece of which is "Single Responsibility". We don't couple things on a whim.