Hacker News new | ask | show | jobs
by shellac 372 days ago
It's a minor thing, but:

> Most of my open source work followed Unix philosophy, so the packages did one thing at a time.

Nobody has suggested that libc -- to take the most obvious example -- is against the Unix philosophy. Debates occur around whether whether commands / daemons do too much (recent poster child being systemd) or aren't composable.

5 comments

If anything, the left-pad debacle has shown that NPM package granularity has gone way too small, at a point where package overhead was outweighing the package simplicity benefits.
Left-pad was made at a time when tree-shaking wasn't really around, so it was good practice to only include the functions you needed to avoid making websites too heavy. If you just needed a small function then it'd be silly to include a huge utility library like Underscore.
You're missing the point. Nobody with a serious background in software development should ever need to pull in a package to pad a string or check if a number is even or odd. If someone is smart enough to use a package manager, they should be more than capable to write a function to pad a string (assuming the standard library doesn't include one already)!
How does serious background help the argument for wasting your time writing code that's already been written. By the way, why should serious people use padding from the standard library?
I would argue that a leftpad/is-odd package is the equivalent of writing a for loop. The time it cost you to search the internet, download the package, and rerun your build script cost more than the time to write the function from scratch and the behavior is indentical.

Duplicate code across the ecosystem is fine. Not every function must be unique for an entire programming language.

What about the time it cost you to search the internet, read the docs, and use the one from std? How many seconds does each variant take (with hot/cold memory cache?)

And the behavior could also be worse, there is no guarantee of perfection.

The last argument is too generic to offer any guidance. Why is it better for this function be duplicated?? Should it not be part of std to avoid uniqueness?

The standard library is a far less risky dependency than third-party libraries. It's far more reliable in presence and behavior.
While you are correct, the problem compounds when popular package developers choose to use tiny packages.

I don't need left-pad.

But maybe I need react-starter-kit.

Now, imagine that react-starter-kit has a dependency to markdown-js-blobber, which has a dependency to make-text-nice, which has a dependency to left-pad.

In this scenario I am now "pulling in a package to pad a string". If I am "smart enough to use a package manager", I should be "more than capable to write..." an alternative to react-starter-kit..?

The onus there is on the "make-text-nice" developer, not an eventual user of "make-text-nice".
I don't place any blame here on the person using `react-starter-kit` and I think you're being a bit obtuse to suggest otherwise. It's the original person who pulled in a package for <10 lines of code who is to blame.
I provided the real reason for the high download counts of these packages.
However, JavaScript never had a proper standard library.

Combine this to mainstream education teaching that you should always reuse code when possible instead of "reinventing the wheel", and web shops agreeing to it because "using libraries saves time", and it's easy to understand the "popularity" of left-pad.

To a certain extent, and to the best of my knowledge, those things haven't really changed.

Ironically I feel like this is something LLMs will improve. Now anyone can type "create left pad function" and it will essentially just vendor in the existing code.
What does the size or granularity have to do with the incident? If the author had combined all his 350+ packages into one (or had had a more comprehensive text-utils.js package) and pulled that instead, the issue would have been at least as severe?

I don’t think such small packages are sensible, in particular when versioned separately, but I also don’t see how the left-pad debacle has shown that.

> Nobody has suggested that libc -- to take the most obvious example -- is against the Unix philosophy.

Plenty of people have suggested that. I'll suggest it for you now if you like. The modern form of libc is very much against the unix philosophy; traditional Unix had a much simpler libc where many functions were just syscalls; some parts of today's libc were hived off into separate libraries like libm, and other parts like NSS and convoluted DNS resolution frameworks just didn't exist at all.

The obverse to 'do one thing' is that you have to do the whole thing.
The "unix philosophy" is a useless philosophy - perhaps worse than useless even - because "one thing" is not well defined, so in practice it adds nothing and just leads to arguments.

You could say that Eclipse does "one thing" - being an IDE platform - but I don't think anyone thinks that's what the Unix devs meant. Similarly I don't think they meant for people to write libraries that contain one 11-line function.

The actual advice should be something like "programs/libraries shouldn't try to do too much or too little". How do you know how much is too much or too little? Like so many programming guidelines the answer is you need taste and experience.

I feel like "do one thing and do it well" is an oversimplification:

(i) Make each program do one thing well. To do a new job, build afresh rather than complicate old programs by adding new "features".

(ii) Expect the output of every program to become the input to another, as yet unknown, program. Don't clutter output with extraneous information. Avoid stringently columnar or binary input formats. Don't insist on interactive input.

(iii) Design and build software, even operating systems, to be tried early, ideally within weeks. Don't hesitate to throw away the clumsy parts and rebuild them.

(iv) Use tools in preference to unskilled help to lighten a programming task, even if you have to detour to build the tools and expect to throw some of them out after you've finished using them

---

[1] https://archive.org/details/bstj57-6-1899/page/n3/mode/2up

I agree with that. And like most rule of thumbs, it's very useful to go beyond the prescriptive part and ask yourself "why". And as qsort described, doing "one thing well" enables you to have desirable traits (easy testability, low cost refactoring, etc.).
> because "one thing" is not well defined

That's what a philosophy is, gives you some general guideline and you have to use your thinking to figure out how to apply it in specific circumstances. It does not substitute that thinking neither does it prevent stupid choices, it helps guide you in a higher/strategic level. It is not responsible for people making stupid decisions.

Sure but my point is that the Unix philosophy is so ambiguous that it leads to more confusion than it helps.

Stating it in a way that makes the ambiguity obvious - "don't make your program do too much" - reveals how little value it contains.

If you consider it from the point of view of how "clear is the scope?" Then it makes more sense.

Libc implementations have a very clear scope, clear enough that you can point to the specification. That is their 'one thing' do what that spec says.

Eclipse however, doesn't have that singular goal. You would be hard pressed to say how many of Eclipse's tentacles is a clear push towards being an ide. What should a completely finished version of Eclipse that met all it's goals look like?

Similarly the one thing could be "be a c preprocessor" or be a full "c compiler" these are both "one thing"s even while one is a subset of the other.

The intention of "do one thing, and do it well" is not to limit the scope but to show the boundary of the scope and to commit to doing everything within that boundary

By making your one thing "a full c compiler" you should be committing to doing everything that someone making a c preprocessor is doing, and to the same standard. The Unix philosophy should be considered a warning not to neglect components because you are working on a larger system.

You can't do everything, but you don't have to. If others are following the same principles then many of the parts of what you need will be done to a high standard by others.

> Libc implementations have a very clear scope, clear enough that you can point to the specification. That is their 'one thing' do what that spec says.

No you can't get out of it my just saying the "one thing" is to do what the spec says. Who decided what's in the spec?

Would Eclipse be fine if someone just wrote a spec for it?

It doesn't matter who decided what's in the spec. What matters is that you decided to implement it to a high standard. It's usefulness to others will be related to what they think of the spec. Nobody has to use your tool, but it's good for everyone to know exactly what the tool is.

Eclipse would be fine if it had a spec, committing to implementing that might be a task to arduous for some. A full spec would also lay bare what its goal is. Which in turn might lead to people deciding the tool they need is not this one. But yes, if was clear what it should be doing and it did that well then everyone benefits.

So the Unix philosophy doesn't apply if you have a written specification for you program? That's a pretty out-there view. I don't see why having a spec is related to what the Unix philosophy is trying to achieve.
The Unix philosophy tells you how to get a powerful interactive programming environment on a 16-bit minicomputer where the maximum text segment size was 64KiB. The libc I'm using on this cellphone is 1MiB, 16× bigger. So at least 90% of libc is against the Unix philosophy.

I don't see how anyone could read the Lions book or APUE, on one hand, and the pthreads manual or the ANSI C specification of setlocale(), on the other, and come to the conclusion that they represent the same philosophy. It's like thinking Ayn Rand is an exponent of the same philosophy as Epicurus; it betrays a staggering lack of sincere engagement with either one.