Code: Select all
> ls --help | wc -l
> man ls | wc -l
I'm actually surprised it's that small. If I copy and paste the ls
section of the GNU coreutils manual into a text file and remove the navigation headers (initially keeping paragraphs all one line):
Code: Select all
evan@picard:~$ wc -l ls.txt
evan@picard:~$ fold -w 80 -s ls.txt | wc -l
And to me, ls
is actually a great
example of a place where the Unix philosophy of piping human-readable text around works extremely poorly. A significant majority of ls
's options are violating "do one thing and do it well." For example, take sorting; more than 1/10 of the manual by lines is talking about ls
's sorting. But why should it be sorting in the first place? We have
a utility that sorts and sorts well... it's called sort
! If the Unix philosophy actually worked well, we'd say something like ls | sort <something saying to sort by size or whatever>
instead of ls --sort=size
. But the fact that ls
"has to" produce human-readable output means that there's no reasonable way to build that pipeline, which means that ls
itself has to implement sorting. And so on for various other things, like timestamp formatting.
Another place I argue
that many of the Unix utils should be built around outputting a semi-structured text format like JSON, which would actually allow you to start composing programs like this. I started working on that actually and got a couple things done, but I haven't done anything for years. (If I quit my job, maybe I'd have time for half of what I want to do.
But the other thing is that, some of the time, you really do want to integrate things. And ls
is also an example of this: because if you don't want to re-design the Unix command-line interface from the utilities at least through the shell, putting --sort
instead of a rigid adherence to the "do one thing" philosophy is the right thing to do.
Wildcard wrote:Is there really any realm of software development where those basics don't hold true as excellent guidelines to follow?
I think if really take a good look at the standard Unix utilities, one of two things is true: (1) a lot of Unix utilities (e.g. ls
) do a poor job at following the Unix philosophy, or (2) the Unix philosophy needs to be broken frequently
. I don't know where you'd fall between those decisions.
So "follow"? No. "Bear in mind?" "Consider?" yes.
KnightExemplar wrote:The greatest part about reading through that documentation was realizing that everything is a file descriptor
...except for xattrs, because who knows. Apparently whoever designed them either forgot they were on Unix or actually hated the fact that they were adding support for them in the first place so deliberately did as bad of a job as they reasonably could.
(Unless there's some API for access I don't know about other than getxattr/setxattr.)