Live data from Hacker News

Write code that is easy to delete, not easy to extend (2016)

programmingisterrible.com

31–40 of 113 posts

Re: Write code that is easy to delete, not easy to extend (2016)

#31
post #23
post #13

Earlier quoted context omitted.

> Also, changing the slightest things required to go through 5-6 files. That is a sign it was incorrectly modularised. Good modularisation means high cohesion and low coupling. Having to make changes in multiple files means the opposite. Don't rack on modularisation (great concept!) when your only experiences are of bad implementations of it. (Which is not surprising, because most people do get it wrong.) Maybe the t…

That sounds like myriads of programmers have done it wrong for decades. Can you elaborate on this and maybe add a few sources?

The ultimate source is David Parnas' 1970s' articles On the Criteria to be Used in Decomposing Systems Into Modules, and Designing for Ease of Extension and Contraction by the same author. The 1960s' NATO conferences on software engineering also touch on this.

These articles essentially introduced modularization, and they argue very well for why their approach is superior to the misunderstanding we frequently see today.

There was a lot of good research into how to build software right back in the '60s and '70s that was mostly ignored/forgotten during the '90s which is when many of the mistaken patterns we see today was invented.

Not much of an elaboration, for which I'm sorry, but I think the original sources are a more efficient use of time than my retelling, for anyone curious.

Edit: I can say one thing in different words than the original papers: one thing you want from your modules is that their interfaces are stable. (This is what's known as "information hiding", i.e. the modules themselves can change as much as you want, but since their interface is stable those changes don't propagate to other parts of the code.)

If you define a module for your routes, then the interface of that module will have to change for literally anything you add or remove to the site. This is the opposite of a stable interface.

Figuring out how to design a stable interface is tricky -- this is why good engineers are worth so much -- but one rule of thumb is to base modules on business domain concepts. The business domain has likely existed for longer than your application, and it's concepts will likely outlive your application. They tend to be stable, compared to whatever implementation details seem reasonable today.

Re: Write code that is easy to delete, not easy to extend (2016)

#33
I think that one possible problem with the 'O' in SOLID (open closed principle) is spending excess time second guessing future modifications to the code. The examples are always clear cut, but in the real world it sometimes doesn't work out that way.

OTOH I'd say that the 'L' is worthwhile (Liskov substitution principle) as inheritance can be abused as a kind of 'version control' for functionality, and LSP helps guard against that.

Re: Write code that is easy to delete, not easy to extend (2016)

#34
post #18
post #10

I wholeheartedly agree with "don't immediately jump on the modularize and abstract everything right away". I think that "modularization and abstraction is always and uniformly good" is one of the big lies of our profession. It’s easy to see how it’s attractive : programming is intellectual work, and displaying capacity of abstraction is rewarding. I was extremely enthusiastic about that stuff when I was young, too. T…

> Loccount on my "ugly, not modular" backend[...] > > all SLOC=2284 (100.00%) LLOC=0 in 13 files > > Loccount on the "very clean" backend of the previous contractor: > > all SLOC=12507 (100.00%) LLOC=0 in 262 files This begs the question: so what? Comparison will only make sense when another pour soul will try and change something on the likely mess you look proud to have created. What you found was not well maintain…

It is arguable whether 2x LOC reduction is worth it. But 5x LOC reduction on the same technology stack kind of changes the complexity category of the code base. 2kLOC (borderline trivial application) is almost always easier to maintain than 12kLOC (small application) — as 60kLOC would be easier to maintain than 12kLOC.

This is valid, of course, only for comparable code, not taking into account obfuscation, complete removal of tests, etc.

Re: Write code that is easy to delete, not easy to extend (2016)

#35
post #25

Earlier quoted context omitted.

Here's his github too, if anyone's interested. Fairly prolific to say the least: https://github.com/tef

most of the commits are empty https://github.com/tef/0.0/commit/59575ac7d888c60eb043fe3b3c...

and they were made in the future

Re: Write code that is easy to delete, not easy to extend (2016)

#36
post #15

The unfortunate side effect of this (very good) advice is that all code that's easy to delete will eventually be replaced with code that's hard to delete (and thus will eventually be impossible to delete in order to be replaced with something better).

It is like the Murphy's law of deletable code "Anything that can be made hard to delete will be made hard to delete".

Good code disappears, bad code stays.

Re: Write code that is easy to delete, not easy to extend (2016)

#38

The unfortunate side effect of this (very good) advice is that all code that's easy to delete will eventually be replaced with code that's hard to delete (and thus will eventually be impossible to delete in order to be replaced with something better).

Actually, beside the facetious aspect of this, there is a subconscious value into having code-mass. Heavy means stable at times.

Re: Write code that is easy to delete, not easy to extend (2016)

#39

The unfortunate side effect of this (very good) advice is that all code that's easy to delete will eventually be replaced with code that's hard to delete (and thus will eventually be impossible to delete in order to be replaced with something better).

Actually, beside the facetious aspect of this, there is a subconscious value into having code-mass. Heavy means stable at times.

I'm not sure what you mean. Evidence indicates that code attracts more code, and big elements are frequently changed.

Re: Write code that is easy to delete, not easy to extend (2016)

#40

I think that one possible problem with the 'O' in SOLID (open closed principle) is spending excess time second guessing future modifications to the code. The examples are always clear cut, but in the real world it sometimes doesn't work out that way. OTOH I'd say that the 'L' is worthwhile (Liskov substitution principle) as inheritance can be abused as a kind of 'version control' for functionality, and LSP helps guar…

[deleted]
Post reply on HN