News for hackers. Stuff that matters.
Re:Kernighan and Pike were right: Do one thing, and do it well by noelwelsh on Saturday August 19, 2023 @02:32AM (#37186144)
The basic point is right, but I think a lot of the details are off. The core idea is composition. A system is compositional if you can build it from small reusable parts. It's one of the key ideas in functional programming, and it's somewhat core to object-oriented programming. (OO is too big to be able to claim their is a consistent philosophy behind it.)

But ... firstly, let's stop with the Unix worship. They didn't deliver, even in the domain of the terminal. My copy of `ls` has at least 40 flags (where I stopped counting). Secondly, people have tried composition on the desktop. That's what CORBA, COM, and OLE were all about. They all kinda sucked for various reasons. Finally, the place at which the author arises has been around for as long as Unix: it's Emacs.

Re:Kernighan and Pike were right: Do one thing, and do it well by pjmlp on Saturday August 19, 2023 @02:34AM (#37186158)
Not only is COM still around, it is the main delivery mechanism for Windows APIs since Vista.

Agree with UNIX worship point, I also had it, I was young and naive, lacking experience in the history of computer systems.

Re:Kernighan and Pike were right: Do one thing, and do it well by noelwelsh on Saturday August 19, 2023 @02:36AM (#37186167)
Wow, I didn't realise. I haven't paid attention to Windows APIs for a long time. I really thought it would have died a long time ago.
Re:Kernighan and Pike were right: Do one thing, and do it well by pjmlp on Saturday August 19, 2023 @02:42AM (#37186184)
That is what people outside Windows keep thinking.

After WinDev managed to botch Longhorn efforts, its .NET ideas were redone in COM for Vista, and it has been like that ever since.

WinRT/UAP/UWP, is basically COM with a new base interface IInspectable, .NET metadata instead of TLB files, and app boxing.

And it is the foundation of WinAppSDK, whose goal is to port UWP subsystem into plain Win32, although their current execution leaves a lot to be desired.

Re:Kernighan and Pike were right: Do one thing, and do it well by dist-epoch on Saturday August 19, 2023 @03:14AM (#37186343)
The core of COM is about allowing binary code to be used from any language through a standardized interface.

As pjmlp mentioned, this part was very successful and all new Windows APIs are based on it.

The COM which failed and which you are thinking about was related to OLE and the idea of embedding Excel sheets inside Photoshop drawings, ...

Re:Kernighan and Pike were right: Do one thing, and do it well by abwizz on Saturday August 19, 2023 @05:25AM (#37187004)
> the idea of embedding Excel sheets inside Photoshop drawings, ...

that's still a thing isn't it?

Re:Kernighan and Pike were right: Do one thing, and do it well by zweifuss on Saturday August 19, 2023 @10:08AM (#37188933)
Microsoft ported OLE 1 to Macintosh, but never OLE Version 2, because Apple guidelines forbid programes to start other programs. Because of that Photoshop had a not supported version of OLE. I don't know if it is still available in up to date Photoshop.

On Windows it works both ways with OLE 2.

Re:Kernighan and Pike were right: Do one thing, and do it well by doctor_eval on Saturday August 19, 2023 @02:56AM (#37186256)
Let's just be careful what we call Unix though. In SVR4, I don't think "ls" had that many options. It didn't even have colour (not that I would know; my Wyse 60 could only have Green, Orange or White text... and the colour was set in the factory).

It's the same for many programs that started small but grew loads of knobs with age. You can't claim that this was the Unix vision, because what we call Unix today isn't even technically Unix.

I'm not saying Linux is bad or anything; I'm just pointing out that it's much more organic than Unix ever was, and that the resulting system is not necessarily carefully orchestrated.

Re:Kernighan and Pike were right: Do one thing, and do it well by noelwelsh on Saturday August 19, 2023 @04:11AM (#37186644)
IMO the problem with the Unix model is not that it's been corrupted over time, but that it was fundamentally flawed from the start. I'm hardly the first to point this out, but sending around unstructured text makes doing some things inordinately hard (imagine writing a separate program to color ls's output, instead of having that as a flag) + going beyond pipes leads to the awful experience of programming in shell.
Re:Kernighan and Pike were right: Do one thing, and do it well by benj111 on Saturday August 19, 2023 @04:31AM (#37186749)
Ls seems like a bad example.

Anything that you'd want to colour, the data should already be there.

Further I'm not sure the Unix way inherently requires completely unstructured text

Re:Kernighan and Pike were right: Do one thing, and do it well by rcxdude on Saturday August 19, 2023 @04:52AM (#37186844)
Unstructured text is the unix way. You can have pipelines sending other things between your programs (see powershell), but that's definitely not Unix.
Re:Kernighan and Pike were right: Do one thing, and do it well by rakoo on Saturday August 19, 2023 @05:59AM (#37187168)
I disagree, the unix way has structure: lines of text each consisting of space-separated fields. The real issue is that sometimes your data has spaces, or even newlines, so the structure quickly isn't enough. And that "sometimes" happens xay more often than it has to, and the escape hatch is a mess.
Re:Kernighan and Pike were right: Do one thing, and do it well by masfuerte on Saturday August 19, 2023 @07:25AM (#37187655)
> lines of text each consisting of space-separated fields

I wish! Back in the day, tools like iostat and vmstat printed tabular data using fixed width fields with no spaces between. This worked fine until the computers got bigger and faster, then the larger numbers filled the fields so they ran together making the output unreadable. A surprising number of vendors had this problem.

Re:Kernighan and Pike were right: Do one thing, and do it well by BirAdam on Saturday August 19, 2023 @11:31AM (#37189767)
But, you can always override IFS, so this isn’t as much of an issue.
Re:Kernighan and Pike were right: Do one thing, and do it well by bobbylarrybobby on Saturday August 19, 2023 @08:24PM (#37194756)
It's bizarre that this is the case given that ascii contains characters for this very purpose. There's record separator, group separator... Now if your data contains those, that's bad. But that's much rarer than containing ordinary whitespace.
Re:Kernighan and Pike were right: Do one thing, and do it well by Kinrany on Saturday August 19, 2023 @06:40AM (#37187387)
I disagree: text is the minimum structure. It's often enough sufficient too, but using something higher level like JSON is also perfectly UNIX.
Re:Kernighan and Pike were right: Do one thing, and do it well by rcxdude on Saturday August 19, 2023 @07:07AM (#37187543)
I don't think so, this idea of JSON is a more modern interpretation and I'd say is counter to the UNIX philosophy, not an extension to it (it just so happens to squeeze into existing primitives a little better than e.g. a binary serialisation protocol).
Re:Kernighan and Pike were right: Do one thing, and do it well by bregma on Saturday August 19, 2023 @07:10AM (#37187568)
The Unix way is streams of bytes.

How those bytes are interpreted is up to the endpoints of the streams. Sure, a lot of endpoints interpret byte streams as text. That's not Unix, that's a particular endpoint.

You will notice that Unix does not even offer 'text' files (like Windows does). Or ISAM files, or random access files. or Fortran carriage control. Just binary files. Because the Unix way is streams of bytes, and nothing more.

Re:Kernighan and Pike were right: Do one thing, and do it well by benj111 on Saturday August 19, 2023 @07:23AM (#37187649)
I disagree, unstructured text is itself fuzzy.

CSV, line delimited, is that unstructured?

Further if you wanted to go with JSON or something you can, there's nothing preventing it. Pipes are based on unstructured text so you have that flexibility. If you want to add JSON ls and filter that through JSON sed to JSON less you can.

Finally 'the Unix way' is a cultural thing. It isn't set in stone. It can, and probably has evolved. So while you could argue that it meant that to some people at some time, that doesn't make it true today or in the future. The down side is that we have these disagreements over what 'the Unix way' is. But any philosophy that's been around for 40 years, in tech no less, has to be flexible, that's why it's stay relevant.

Re:Kernighan and Pike were right: Do one thing, and do it well by AnimalMuppet on Saturday August 19, 2023 @11:17AM (#37189624)
The Unix command line tools were designed to be usable in a lot of ad hoc situations. In an ad hoc situation, unstructured text is often what you have. So, to be usable for that, the command line tools had to be able to operate on unstructured text as input. That left two options - either also accept something structured as input, or accept only unstructured text as input.

"Usable in an ad hoc situation" gets us back to composability. If you can compose existing parts to meet a novel situation, that's better than having to carefully architect a solution. And the key to being able to do that is common interfaces. Unix did exactly that. And, for all the criticism, it works pretty well.

Can a well-designed interface do better? Sure. Can a well-designed interface deal with something outside the design parameters as well? Probably not.

Re:Kernighan and Pike were right: Do one thing, and do it well by grumblingdev on Saturday August 19, 2023 @04:40PM (#37192943)
I mean people still use `ls` everyday so it in fact did win. We have super rich GUIs, REPLs, the start menu, live programming environments and notebooks, web browser file listing capability, the ability to build your own web app to list files visually anyway you want.

And yet everyone still uses `ls`.

Re:Kernighan and Pike were right: Do one thing, and do it well by tmtvl on Saturday August 19, 2023 @06:45PM (#37194103)
I think that most people who need ls's functionality (listing files in a directory) use a GUI application.
Re:Kernighan and Pike were right: Do one thing, and do it well by AnimalMuppet on Saturday August 19, 2023 @07:41PM (#37194484)
Depends on how you define "functionality". You could say that ls's functionality is "providing a text listing of files in a directory. You can't get that from a GUI, certainly not without extra steps.

Why would anyone care about that difference? If I'm reading the listing, I don't care. My eyeballs don't care if the photons came from a GUI or text in a shell. But if I'm trying to pipe the results to another program, then I care. GUIs don't pipe well.

And people like me pipe the results of ls all the time.

Re:Kernighan and Pike were right: Do one thing, and do it well by tsimionescu on Saturday August 19, 2023 @04:23AM (#37186703)
It's still a failing of the Unix philosophy that people found it easier to add all these flags to ls than to string together a few "simple&composable" commands.
Re:Kernighan and Pike were right: Do one thing, and do it well by jcelerier on Saturday August 19, 2023 @01:53PM (#37191314)
It's for the very simple reason that flags are more easily discoverable (with simply a couple of tab key presses I can iterate and see the list of most flags of most of the cli apps I use) than "whichever program amongst the 7362 executables with obscure names I apparently have in /usr/bin will do the thing I want"
Re:Kernighan and Pike were right: Do one thing, and do it well by grumblingdev on Saturday August 19, 2023 @05:44PM (#37193576)
I guess they could have implemented some of the flags as aliases or rather bash functions to a preset chain of invocations. The merging of flags would be difficult though.

There are many flags that change the behavior of the file system calls that would be made...such as getting additional information.

To support all the formatting commands, the piped output of `ls` would need to be very verbose and structured too...like json or something.

They had to draw boundaries of functionality at some point.

So the unix idea of "one thing" was probably defined a bit more vaguely or more end-user use case related. Convenience seemed to be king.

It would have be nicer if they could have added a shell-like pipe syntax to C (and designed the code in a more modular and stream-like way).

In the `ls` [source code][1] you can see simple blocks of steps like:

    if (!file_ignored(file)) {
      ...
      sort_files ();
      print_current_files ();
      clear_files ();   
    }
For example the `file_ignored` function in `ls` would have made a nice reusable library (with standardized configuration params) and a cli tool (with standardized flags).

Missed opportunity to unify the shell and C, but I guess SmallTalk was kicking around at that time which went a whole lot further.

It's funny that we are still very much lacking this unification...

We don't have a high-level interpreted language that can also perform well as a system's language.

New systems languages are popping up all the time, but they are more and more hardcore (looking at you Rust). They don't embrace any aspect of scriptability.

The best effort I can think of is https://www.modular.com/.

Surely though, a native TypeScript-based language is the way. It by far has the nicest syntax out of the popular scripting languages today.

We have come so close...like with Dart...but still everyone seems to be avoiding the inevitability.

[1]: https://github.com/wertarbyte/coreutils/blob/master/src/ls.c

Re:Kernighan and Pike were right: Do one thing, and do it well by eesmith on Saturday August 19, 2023 @06:27AM (#37187314)
FWIW, ls in Research-V6 back in 1975 had 10 options. https://github.com/dspinellis/unix-history-repo/blob/Researc...

By BSD 3 in 1980 it had 11 options. https://github.com/dspinellis/unix-history-repo/blob/BSD-3-S...

The thing is, we can see even from the 1970s 'ls' how the Unix model doesn't meet the goal "to chain these simple programs together to create complex behaviors".

There is no option to escape or NUL terminate a filename, making it possible to construct a filename containing a newline which makes the output look like two file entries.

The option for that was added later.

There's also the issue that embedded terminal codes will be interpreted by the terminal.

Re:Kernighan and Pike were right: Do one thing, and do it well by throwaway31381 on Saturday August 19, 2023 @04:55AM (#37186855)
>But ... firstly, let's stop with the Unix worship. They didn't deliver, even in the domain of the terminal. My copy of `ls` has at least 40 flags

GNU is Not Unix.

I count 13 flags on both Unix V10 [1] and on Plan 9 [2], its spiritual successor.

[1] http://man.cat-v.org/unix_10th/1/ls

[2] http://man.cat-v.org/plan_9/1/ls

Re:Kernighan and Pike were right: Do one thing, and do it well by cpach on Saturday August 19, 2023 @05:20AM (#37186980)
I think you’re actually making the point for him here. You are correct that GNU is not Unix. And what version of ls has the most installations? I betcha it’s the ls from GNU Coreutils. I do agree that GNU tools are sometimes too maximalist. But they are also more useful than the minimalist alternatives.
Re:Kernighan and Pike were right: Do one thing, and do it well by tuukkah on Saturday August 19, 2023 @05:34AM (#37187042)
To me, the point is you don't need many flags for ls to be useful. You will learn a few idioms early, such as ls -a and ls -lR but after that, the rest of the flags are nice to haves: if you wish there was a certain feature, you can look it up on the man pages etc. "I wish I could sort by time - oh there's -t"
Re:Kernighan and Pike were right: Do one thing, and do it well by abwizz on Saturday August 19, 2023 @05:27AM (#37187014)
seems like you agree that the extra flags make sense
Re:Kernighan and Pike were right: Do one thing, and do it well by cpach on Saturday August 19, 2023 @05:32AM (#37187038)
In many cases, yes! On my Mac, which has a userland derived from FreeBSD, I have voluntarily installed stuff like GNU Findutils and GNU sed to get that extra functionality.
Re:Kernighan and Pike were right: Do one thing, and do it well by throwaway31381 on Saturday August 19, 2023 @06:07AM (#37187204)
I don't believe GNU's triumph over the BSD derivates was for the most part technical, they just happened to be at the right moment at the right time to ride along Linux's success.

A consequence of the proliferation of arguments in the GNU tools is imho that it made the GNU manpages too verbose and information dense to the detriment of their usefulness.

Re:Kernighan and Pike were right: Do one thing, and do it well by cpach on Saturday August 19, 2023 @06:18AM (#37187262)
Good point. However: The users could have revolted and gone to *BSD land instead. But for some reason, most users didn’t.
Re:Kernighan and Pike were right: Do one thing, and do it well by jmclnx on Saturday August 19, 2023 @10:35AM (#37189218)
That is because of the "lawsuite", unless you are referring to the 80s.

Back then, Companies and Colleges were the ones who got UNIX. Companies went with AT&T, and IIRC Colleges when with BSD. So AT&T won out due to better financial backing and maybe a possible threat of AT&T going after BSD.

Re:Kernighan and Pike were right: Do one thing, and do it well by cpach on Saturday August 19, 2023 @11:22AM (#37189665)
Well, Linux is 30 now. The lawsuite was settled quite long ago, wasn’t it?
Re:Kernighan and Pike were right: Do one thing, and do it well by jmclnx on Saturday August 19, 2023 @06:20PM (#37193911)
You did not specify a timeline. The book was written in 1984, BSD existed then and the only other UNIX was AT&T. Linux was not even a dream in 1984.
Re:Kernighan and Pike were right: Do one thing, and do it well by jacquesm on Saturday August 19, 2023 @07:06AM (#37187534)
That's exactly why RMS is so pissed at Linux being mentioned without GNU. The funny thing is that it is the license he shipped his code under that allowed them to do this, he could have made the license say 'if you use this code you are required to prefix the name of any project with 'GNU/'' and that would have been that. If you give people rights and freedom they will use them.
Re:Kernighan and Pike were right: Do one thing, and do it well by toast0 on Saturday August 19, 2023 @12:10PM (#37190205)
If he wanted advertising/acknowledgement, he might have considered the BSD license instead.
Re:Kernighan and Pike were right: Do one thing, and do it well by noelwelsh on Saturday August 19, 2023 @05:53AM (#37187143)
This is a version of a No True Scotsman argument: the True Unix did not have these flags and therefore these flags are not part of the Unix Way. The extra flags were added over time because the One True Unix did not provide the functionality that people needed in real world use. They couldn't be added in a composable way because of failures in the shell programming model (unstructured text + sh is terrible). The Unix shell model was broken from the start.
Re:Kernighan and Pike were right: Do one thing, and do it well by throwaway31381 on Saturday August 19, 2023 @06:43AM (#37187402)
I won't deny the useful additions GNU and BSD made to the barebones UNIX tools, but just by skimming the ls man page I can list some flags whose addition wasn't caused by the Unix Philosophy's limitation:

  -1 list one file per line
  -C list entries by columns
  -t sort by time, newest first; see --time
  -r, --reverse reverse order while sorting
  -S sort by file size, largest first
  --sort=WORD sort by WORD instead of name: none (-U), size (- 
  S), time (-t), version (-v), extension (-X), width
Re:Kernighan and Pike were right: Do one thing, and do it well by edgyquant on Saturday August 19, 2023 @09:32AM (#37188619)
No that’s literally what GNU stands for.
Re:Kernighan and Pike were right: Do one thing, and do it well by loph on Saturday August 19, 2023 @09:55AM (#37188826)
I hold in my hand a "Unix Reference Card," second edition, March 1979.

There are 10 options listed for "ls":

l, f, a, s, d, r, u, c, i, f, g

My recollection is that this card was for Unix V7.

Re:Kernighan and Pike were right: Do one thing, and do it well by libele on Saturday August 19, 2023 @02:18PM (#37191558)
the "purple card" of myth and legend!? please take a picture.
Re:Kernighan and Pike were right: Do one thing, and do it well by loph on Wednesday August 23, 2023 @09:40AM (#37235671)
Re:Kernighan and Pike were right: Do one thing, and do it well by dgb23 on Saturday August 19, 2023 @09:32AM (#37188615)
Composable systems have a very clear property: uniform interfaces.

CLI flags are typically arbitrary. What if they weren’t? How would they look like?

Re:Kernighan and Pike were right: Do one thing, and do it well by throw16180339 on Saturday August 19, 2023 @12:09PM (#37190188)
PowerShell has fairly uniform interfaces.
Re:Kernighan and Pike were right: Do one thing, and do it well by mannykannot on Saturday August 19, 2023 @10:01AM (#37188883)
Yes, ls does have a lot of flags, but how did it get them, and what are the alternatives? It got them to satisfy real needs, and using flags, especially when combined with having man at your fingertips, was (and is) a highly effective interface for interactive work. If there is anything to be learned from the proliferation of command-line flags, it might be that one should not attribute too much significance to a vague aphorism such as "do one thing, and do it well."
Re:Kernighan and Pike were right: Do one thing, and do it well by docfort on Saturday August 19, 2023 @12:04PM (#37190126)
I agree that composition is the core idea and I was disappointed that the author neglected to summarize the idea correctly. Composition is a structured way of describing a unique task using a few common nouns and verbs.

But composition needs to be understandable and controllable to be useful.

For it to be understandable, it needs to match the user’s anticipated mental model. Now, this isn’t an appeal to an intuitive notion uninformed by user education. But it does need to make logical sense to connect two things together temporarily to solve one task. And that logic needs to come from the user and not the developer. In other words, the developer needs to provide concepts that conform to a user’s algebra. For a photo editor, that’s hard to provide to the average user. For some CLI tools like wc and cat, it is easy.

For composition to be controllable, the primary method of configuration needs to be in the contextual relationships among the tools and not in the tools themselves. That is, using cat and wc to count the number of words in a text file is primarily enabled by the filesystem and shell features, none of which require user configuration during the operation. Configuring wc to count instead the number of lines doesn’t distract too much, but imagine counting the number of lines emitted from a streaming serial device: you want it unbuffered, but only kinda because of other issues that arise, like multiline error conditions. In that case, the value is disrupted by edge cases and you have to configure the nouns (the serial stream at least) by looking it up on Stack Overflow. It’s not just easier to consider building a monolithic tool, but arguably the right thing to do because you need to configure everything so much. Plus, this is too much to expect the user to handle through a simple composition.

In my opinion, desktop composition doesn’t work because the tasks are often beyond the limits of composition. And without a culture of composition among users, it’s harder and harder for remaining desktop applications to do it. Especially as younger users are unfamiliar with concepts like the filesystem, system keyboard shortcuts, “saving” files, offline operation (i.e. you have to reason through a problem and cannot lookup the answer), etc. Better to go with the monolithic app model, which can still use plugins under the hood or multiple processes for developer productivity. And I’m sad about that.

Re:Kernighan and Pike were right: Do one thing, and do it well by RetroTechie on Saturday August 19, 2023 @01:57PM (#37191353)
> A system is compositional if you can build it from small reusable parts.

Take big monolith. Refactor into 1001 pieces. Glue together again.

If glue is inflexible, then result is monolith+glue.

If glue is thick, then result is mostly glue + little bits of monolith.

If glue is superb (well designed & flexible), the whole works the same as monolith, but pieces can easily be rearranged as needed (and individually tested!).

Designing good glue is HARD! And then some.

Re:Kernighan and Pike were right: Do one thing, and do it well by grumblingdev on Saturday August 19, 2023 @04:18PM (#37192731)
> My copy of `ls` has at least 40 flags

Good point.

You have to hand it to them though, that shell commands are still the least-typing way to do something compared to every programming language out there.

Like if you gave the user an always-on JavaScript or Python repl, shell commands are still going to win every time.

There are so many JS functions I have that I wish would just get automatic cli interfaces...instead of having to go through the ceremony, or use a repl, or something like that.