Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Write programs that do one thing and do it well

I can grasp the part "do one thing" via encapsulation, Dependency Injection, Principle of Least Knowledge, and You Ain't Gonna Need It; but how do I understand the second part "do it well?"

An example given was the notion of completeness, given in the same YAGNI article:

for example, among features which allow adding items, deleting items, or modifying items, completeness could be used to also recommend "renaming items".

However, I found reasoning like that could easily be abused into feature creep, thus violating the "do one thing" part.

So, what is a litmus test for seeing rather a feature belongs to the "do it well" category (hence, include it into the function/class/program) or to the other "do one thing" category (hence, exclude it)?

The first part, "do one thing," is best understood via UNIX's ls command as a counterexample for its inclusion of excessive number of flags for formatting its output, which should have been completely delegated to another external program. But I don't have a good example to see the second part "do it well."

What is a good example where removing any further feature would make it not "do it well?"

like image 968
kirakun Avatar asked Mar 29 '11 21:03

kirakun


People also ask

Do one thing and do it well programming?

“Unix was created to solve a few problems,” said Dr [Peter] Salus, “the most important of which was to have something that was much more compact than the operating systems that were current at that time which ran on the dinosaurs of the computer age.” The UNIX philosophy is “Do one thing, and do it well.” Rather than ...

What is the philosophy of Linux?

Linux treats everyone equally and allows everyone the maximum amount of power. That is egalitarian. Other operating systems are elitist and exclusive because they withhold or hide their power behind an inflexible Graphical User Interface that allows one to do only what the developers think we should be allowed to do.

In what year was the concept of the pipe which defines and represents so much of the general Unix philosophy was first implemented?

The concept of the pipe, which defines and rep- resents so much of the general Unix philosophy, was first implemented in 1973[10], and we still haven't figured out a better, simpler, or more scalable way for two unrelated processes to communicate with each other.

Why is Unix good for programming?

The answer is simple: Many developers find it's a refreshing alternative to the monolithic tools like IDEs and languages like Java. Instead of being handed down from on high by some corporation, modern Unix versions grow organically.


1 Answers

I see "Do It Well" as being as much about quality of implementation of a function than about the completeness of a set functions (in your example having rename, as well as create and delete).

Do It Well manifests in many ways, some ways of thinking:

Behaviour in response to "special" inputs. Example, calculating the mean of some integers:

int mean(int[] values) { ... }

what does this do if the array has zero elements? If the items total more than MAX_INT?

Performance Characteristics. Has sufficient attention been given to behaviour as the data volumes increase?

Dependency Failures. If our implementation depends upon other modules or infrastructure what happens when these fail. Example: File System Full, Database Down?

Concerning feature creep itself, I think you're correct to indentify a tension here. One thing you might consider: you don't need to implment every feature providing that it's pretty obvious that a feature can be added easily without a complete rewrite.

like image 106
djna Avatar answered Sep 17 '22 16:09

djna