Write code that is easy to delete, not easy to extend (programmingisterrible.com)
from roadrunner_ex@lemmy.ca to programming@programming.dev on 29 Oct 2024 17:16
https://lemmy.ca/post/31921077

#programming

threaded - newest

drspod@lemmy.ml on 29 Oct 2024 17:52 next collapse

“Every line of code is written without reason, maintained out of weakness, and deleted by chance” Jean-Paul Sartre’s Programming in ANSI C

Is this a joke or an AI hallucination? I’m pretty sure Sartre never wrote about programming in ANSI C.

There is a book called “Programming in ANSI C” by E. Balagurusamy

I can only find other references to this quote from sites that are linking this article.

The article actually does date back to 2016 so it’s not AI generated.

drspod@lemmy.ml on 29 Oct 2024 18:44 collapse

I should have tried a bit harder to search, the original quote by Sartre is:

“Every existing thing is born without reason, prolongs itself out of weakness, and dies by chance.”

Evotech@lemmy.world on 31 Oct 2024 09:08 collapse

Thanks for checking

Lysergid@lemmy.ml on 29 Oct 2024 19:41 next collapse

TLDR;

My current project has mostly easy to delete code and not easy to extend. Why? Coz shit was copy-pasted 50 times. It’s not fun to work in this project.

yournameplease@programming.dev on 30 Oct 2024 00:26 next collapse

Same thing on my project. Thousands of lines across a few dozen files copied 100+ times. At that point there’s almost no going back with everything diverging so long ago.

Kache@lemm.ee on 30 Oct 2024 01:36 next collapse

I don’t understand, if you’ve got easy to delete copy-pasted code, then delete it. It’ll be a nice and cathartic exercise.

But sounds like what you’re really talking about is code that isn’t easy to delete.

Lysergid@lemmy.ml on 30 Oct 2024 22:27 collapse

I don’t understand too. Are you suggesting me to drop bunch of features in the product?

samus7070@programming.dev on 31 Oct 2024 02:48 next collapse

I think the responder means that duplicate code is usually easy to refactor into single methods. Typically I see copy pasted code that is changed just a little bit. However much of a duplicated function can be broken into smaller functions and the redundant code removed in favor of calling into the functions. Often what is left then becomes easier to reason about and refactor accordingly. I love the PRs that I make which delete more code than I add but still manage to add functionality. It doesn’t happen often but it’s fun when it does.

Lysergid@lemmy.ml on 31 Oct 2024 08:13 collapse

Right, but my initial comment was about article’s statement being wrong. Refactoring in the way you described will make code harder to delete which is bad according to the article.

Evotech@lemmy.world on 31 Oct 2024 09:07 collapse

Sounds like you read the first paragraph only

Lysergid@lemmy.ml on 31 Oct 2024 13:24 collapse

No, title only

tyler@programming.dev on 31 Oct 2024 12:36 collapse

That means it’s not easy to delete. So your initial premise is wrong.

Lysergid@lemmy.ml on 31 Oct 2024 13:41 collapse

No, that means you falling into author’s bait where they misuse term “delete”. Refactoring is not equal to deleting. One can be result of another. But the truth is that extendable code needs to be modular to be extendable. And modular code is easy to refactor. Author couldn’t not name it “Write code that is easy to refactor, not easy to extend” coz it’s even more dumb

VoterFrog@lemmy.world on 01 Nov 2024 12:23 collapse

Eh, not really then. If you have some behavior in those 50 copy/pastes that needs to be deleted, you’ve got to delete it 50 times. That’s not easier at all.

lascapi@jlai.lu on 29 Oct 2024 20:54 next collapse

Some though are interesting. 🤔

FlorianSimon@sh.itjust.works on 30 Oct 2024 03:54 next collapse

I’d go easy with the recommendation to couple components loosely. If you make things that belong together loosely coupled, you’ve created obfuscation, and added complexity to your codebase. Loose coupling makes sense, but not everywhere.

jim@programming.dev on 30 Oct 2024 08:23 next collapse

This is a classic piece, and I love the contradictions in the text. It encapsulates my feelings on good software and code that it almost becomes an art than a science.

SquiffSquiff@lemmy.world on 30 Oct 2024 20:31 next collapse

Looks like it’s too easy to delete. I click on the link and I get a not found exception

Feathercrown@lemmy.world on 31 Oct 2024 14:01 collapse

Code that’s easy to extend generally encourages creating related code that’s easy to delete. These are very similar directives.