Hacker News new | ask | show | jobs
by mmarx 3562 days ago
> The easier it is to remove code from someone else's program, the "cleaner" the code.

But then, contrary to intuition, a program becomes less clean by actually removing code (since now there is less code to remove, hence it is more difficult to remove code). A minimal (in the sense that no more code can be removed) program would be maximally unclean, whereas, intuitively, should it not be considered clean?

Also, adding code always makes a program cleaner, since the newly added code can always be removed easily.

1 comments

"... in the sense that mo more code can be removed"

Or else what happens?

"... should it not be considered clean?"

It should be considered finished.

"... since the newly added code can always be removed easily."

Not true in my experience. Unfortunately.

Sometimes it's necessary to add some code, e.g., a new driver for a new item of hardware. I have nothing against adding, per se.

> Or else what happens?

In the extreme case (the empty program), there is no more code left to remove. It suffices that any proper subset of the code is insufficient to provide the needed functionality, though.

> It should be considered finished.

And yet you obtain a cleaner version of the finished program by adding superfluous code to it. In fact, every unfinished version (a version where you can still remove code) of the program is cleaner than a finished version (where there is no code left to remove) of it.

> Not true in my experience. Unfortunately.

Removing the code is reverting back to the previous version. How is that not easy to do?

> Sometimes it's necessary to add some code, e.g., a new driver for a new item of hardware. I have nothing against adding, per se.

But that changes the requirements, and thus changes which code can be removed.

However, the point was that you could obtain an arbitrarily clean version of a program by adding redundant code to it—since it's easy to remove that code, it is cleaner than the irredundant version of the program.

"How is that not easy to do?"

1. The author does not provide access to his/her source code repository, only compressed tarballs.

2. The author's code is not clean.

You appear to have some issue with my "definition" of clean code. I do not follow your points but maybe I can state it another way: Code that is easy to edit is clean code. If that definition is still giving you trouble, you think it's unreasonable, etc., let me know.