3 ms·
To add to his point about copy and pasting... Notice the contradiction implicit in these bits of accepted dogma: 1. Copy and pasting code is evil (DRY). 2. T
by jonahx 11y ago
To add to his point about copy and pasting...
Notice the contradiction implicit in these bits of accepted dogma:
1. Copy and pasting code is evil (DRY).
2. Tight coupling is bad, loose coupling is good.
A system written with no abstracted functions (ie, where copy/pasting was the rule) has no coupling. Of course, I'm not advocating such a style. But it's worth keeping in mind that practicing DRY through abstraction necessarily increases coupling, which means that it's always a tradeoff and that you have to get your abstraction right so that the coupling, on average, makes change easier rather than harder.
- arjie 11y agoThat's not really true, is it? Coupling is independent from explicit code dependencies. Take, for instance, two programs. One writes to "/tmp/file". The other reads from "/tmp/file" but neither shares the code to determine the path ("/tmp/file", in this case). They're code independent, but very tightly coupled. In fact, I'd hypothesise that copy-paste codebases are more tightly coupled than otherwise.
- jonahx 11y agoIt's certainly true. Coupling measures the degree of interdependence between modules/functions/classes. If everything is copy/pasted, no module depends on any other -- it simply has its own copy of the code. This will result in a terrible system, but it will be very loosely coupled. When you change something, you won't have to worry about it's impact on anything else. In your example, if the content of the file is changing the behavior of the program reading it, then the programs are sharing code via the file. It just happens to be going on at runtime rather than at compile time.
- stepanhruda 11y agoIf you need to delete code in a codebase full of copy pastes, it's likely that you will need to delete it in many many places and miss some of them. So although the code isn't coupled, it is hard to delete.
- randallsquared 11y agoIn this case, the code is coupled; it's just that it's coupled through the programmer. :/
- tel 11y agoI think that was always implicit and intentional. There really is a tension here. Artful programming rides that tension and understands when (1) is worse than (2) or visa versa. A standard rule of thumb for this tension is the old "rule of three" but it's just a rule of thumb.
- deleted 11y ago[deleted]