3 ms·
> The Single Responsibility Principle says that code should only do one thing. Another framing is that it should have “one reason to change”. I called this the
by eternalban 6y ago
> The Single Responsibility Principle says that code should only do one thing. Another framing is that it should have “one reason to change”. I called this the “Pointlessly Vague Principle”. What is one thing anyway? Is ETL – Extract-Transform-Load – one thing (a DataProcessor) or three things? Any non-trivial code can have any number of reasons to change, which may or may not include the one you had in mind, so again this doesn’t make much sense to me.
The strawman here is the fallacy that SOLID (SRtC) is clearly not saying that a software, composed of "code", should only do one thing. By that reasoning, SOLID rules out any software that provide multiple capabilities. Your editor, for example, has multiple capabilities. It can save. It can highlight. It can cut. It can paste.
So, a reasonable reading of SOLID naturally is not ruling out composing complex software using "simple single purpose code". However, OP is assuming a ridiculous reading (the strawman) that basically can only be valid for software that has only one irreducible capability.
One can read SOLID SRtC in terms of capability as "compose complex software using single purpose code".
One can read SOLID SRtC in terms of change as "changes to code should consist of one, or a sequential set of, single purpose changes".
- coldtea 6y ago>The strawman here is the fallacy that SOLID (SRtC) is clearly not saying that a software, composed of "code", should only do one thing. By that reasoning, SOLID rules out any software that provide multiple capabilities. Your editor, for example, has multiple capabilities. It can save. It can highlight. It can cut. It can paste. That's not what TFA says here. It doesn't claim that SOLID says that software as in 'a full program' should do one thing. It just says that SOLID says that a piece of code (as in a function or a class) should do one thing, which SOLID does say, and which the author of TFA disagrees with. Perhaps the use of the word "code" (or "non-trivial code") is confusing, but the author doesn't imply the whole program with that, but the same as SOLID does (a unit of code): "Code should fit in your head at any level of granularity, whether it is at method/function level, class/module level, components made up of classes, or entire distributed applications".
- eternalban 6y agoDid we read the same thing? How can an "ETL" that he uses as example be just a "function or class"? If he meant simply function, then, you'd have 4 classes (ETL, E, T, L) each doing "one thing" and his entire argument would be moot.