The "loop and a half"

Steve D'Aprano steve+python at pearwood.info
Thu Oct 5 21:07:56 EDT 2017


On Fri, 6 Oct 2017 09:57 am, Marko Rauhamaa wrote:

[quoting Bart]
>>> Yes, I tried typing 'sort' in Linux, where it apparently hangs (same
>>> on Windows actually). The reason: because it might have killed
>>> someone to have added a message saying what you are expected to type
>>> and how to end it. (Namely, press Ctrl-D start at the start of a line
>>> in Linux, and Ctrl-Z followed by Enter, I think also at the start, in
>>> Windows.)

Waiting for input isn't "hangs". That's an ignorant and foolish thing to say,
more suited for a wet-behind-the-ears newbie than somebody who claims to be a
long-time old-school programmer.


[Greg]
>> How to signal EOF from the keyboard is a fundamental piece of
>> knowledge about the OS.

Indeed.

The Unix commandline interface is not designed to be user-friendly for newbies
(or experts, for that matter). It is terse, often *painfully* so (would it
have killed the author to have spelled `umount` correctly?), the UI is
inconsistent, and it has a very steep learning curve -- a lot of effort is
required to make a little bit of progress.

But even a dilettante Unix user like me knows how to signal EOF. It is one of
a handful of indispensable skills you need to use Unix effectively, just as
you can't use Windows effectively without knowing how to right-click. Some
things you just have to learn.

[Marko]
> As for informational messages, it is part of deep-seated Unix culture to
> have quiet commands. The purpose of the silence is so you can easily
> compose new commands out of existing commands via pipelines and scripts.
> It would be inconvenient if you typed the command:
> 
>     grep ython message.txt | sort
> 
> and the sort command instructed you to press Ctrl-D.

Indeed it would.

But in fairness, if the author of the `sort` command had a commitment to
friendliness in their programs, they could have `sort` only print a message
when it is reading from stdin and writing to stdout, much as `ls` defaults to
outputting control characters but automatically swaps to replacing them
with ? when writing to a terminal.

I believe that even Unix experts would be more effective with a judicious
amount of not so much hand-holding as gentle guidance. Even experts aren't
expert on every single command line tool.

But the OS is what it is, and the culture has a certain level of commandline
machismo, so that's unlikely to change.



-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.




More information about the Python-list mailing list