Live data from Hacker News

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

programmingisterrible.com

71–80 of 113 posts

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

#71

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's not a side effect, but a rule of Nature.

It will happen either you follow the advice or not, and the article is about how to slow that process down.

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

#72
post #69

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).

I think the one thing we do wrong with code is when we document it, we write what the function does. Code is largely self-documenting and this because stale quickly anyway. IMO, the thing we should be doing is documenting WHY this function needs to exist. That is the question that is hard to answer three years later.

I like your comment, but for the wrong reason: Explaining what a method DOES, goes against encapsulation principles. It creates coupling to implementation details, when what should be provided is just the interface. Any explanation can be exposed in business domain logic and documentation.

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

#73

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).

Many people argue systemd is an example of code that’s easy to delete being replaced with code that’s hard to delete.

They’ve deleted init, the dns client, dhcpd, the whole xdm family, various small open desktop protocols, kernel-level file permissions enforcement on certain device files, rsyslog, countless shell scripts for running background tasks via ssh, and I’m sure hundreds, if not thousands, of other well-modularized programs. None of the collateral damage is in subsystems related to init. Instead, it is subsystems that worked well, but that were easy to delete.

One the other side of the coin, look at all the effort people are spending to rip systemd out. Multiple Linux distributions exist solely to contain the damage it’s doing.

It’s unclear if gnome will even survive the war if systemd loses.

It’s also wasting the time of end users, so the damage can greatly exceed the total resources put into building Linux distributions.

A few days ago, I ran an “apt-get fullupgade” on my headless Raspberry Pi, and some systemd subsystem wedged during the upgrade. Now networking is broken. I want to use this raspberry pi in an embedded I2C application that run for last decades. So, I need to find an operating system that:

(a) doesn’t use systemd - fool me once, shame on you, fool me twice, well this is well past the second time.

(b) runs on raspberry pi

(c) has userspace tools to work with the i2c bus on the pi

(d) has a working upgrade path.

This is a huge pain, and it’s all to delete one software package that I don’t even care about, and that is irrelevant to the use case for this machine.

/rant

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

#74

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).

A good example of that is adding boost to your code base. Once you've added boost to implement one simple feature, eventually someone will use boost to do preprocessor magic or other meta-programming. Then there is no going back, because there is (almost) no way you will be able to reverse that decision.

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

#76
post #65
post #28

Earlier quoted context omitted.

More like a variant of the Peter principle: all code tends to be refactored to its level of unrefactorability.

I was thinking this too, but on closer scrutiny I don’t think it’s true unless the “goal” of code is to be rewritten. If the goal of code is to work as well as needed and no more, then it won’t move in that direction. The “goal” of employees in a corporate environment can be to be promoted and get paid more, on the other hand, leading to the Peter principle.

I can live happily without promotions, as long as “pay me more” part is working.

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

#77
post #69

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).

I think the one thing we do wrong with code is when we document it, we write what the function does. Code is largely self-documenting and this because stale quickly anyway. IMO, the thing we should be doing is documenting WHY this function needs to exist. That is the question that is hard to answer three years later.

I am working on some code I last touched 12 years ago. I think good documentation is essential, it saves time in the long run. Knowing the why is very helpful.

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

#78
post #17

This was part of the initial idea of extension. David Parnas' 1970's paper that popularised the term was called Designing for the Ease of Extension and Contraction where "ease of contraction" refers to subsettability , i.e. removing parts of the code without having to change other parts. These original papers are well worth a read!

Thanks for the reference. I've read some of his writing, but had not seen this one. I've submitted it here [0].

[0] https://news.ycombinator.com/item?id=23917627

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

#79
post #73

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).

Many people argue systemd is an example of code that’s easy to delete being replaced with code that’s hard to delete. They’ve deleted init, the dns client, dhcpd, the whole xdm family, various small open desktop protocols, kernel-level file permissions enforcement on certain device files, rsyslog, countless shell scripts for running background tasks via ssh, and I’m sure hundreds, if not thousands, of other well-modu…

You might be able to put something together using Raspup or Ultibo. IIRC, both should be able to run on all Pi models. Both are pretty lightweight, simple, and they could be a good base for building what you are looking for.

Raspup is a Puppy Linux for Raspberry Pi. It uses Raspbian Buster as base. I haven't messed with I2C on my Pi, but if there are any userspace tools in Raspbian Buster's repo then you can use them on Raspup. The working upgrade path is the biggest annoyance here. Package management on Puppy in general is a pain for anything but simple install and removal. It seems like the Puppy community either doesn't upgrade or upgrades by installing the next Puppy version (which is usually fast).

Ultibo is not Linux but a Free Pascal kernel that doesn't implement a complete OS. It is for using a Raspberry Pi board more like a microcontroller, but you can use it as a base for anything. For example, someone made a Z80 CP/M emulator that runs pretty fast. Besides the Free Pascal library, the tools here are pretty much what you write. This is probably the simplest option for a Pi that may be alright if you don't plan on using the full functionality of a Linux machine or you want to avoid the Linux kernel scheduler.

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

#80
post #72
post #69

Earlier quoted context omitted.

I think the one thing we do wrong with code is when we document it, we write what the function does. Code is largely self-documenting and this because stale quickly anyway. IMO, the thing we should be doing is documenting WHY this function needs to exist. That is the question that is hard to answer three years later.

I like your comment, but for the wrong reason: Explaining what a method DOES, goes against encapsulation principles. It creates coupling to implementation details, when what should be provided is just the interface. Any explanation can be exposed in business domain logic and documentation.

There are multiple pieces of documentation. Documenting what a method does is one of them, but primarily intended for maintainers of the system. Documenting its interface is meant for its users.

Both have great value, but at different times and to different people.

Post reply on HN