The "loop and a half"

Steve D'Aprano steve+python at pearwood.info
Sat Oct 7 05:43:02 EDT 2017


On Sat, 7 Oct 2017 07:01 am, bartc wrote:

> On 06/10/2017 20:38, Grant Edwards wrote:
>> On 2017-10-06, bartc <bc at freeuk.com> wrote:
>> 
>>> For sort, there is no real need. You use a text editor to create
>>> your data. Then use existing file-based sort.
>> 
>> I sort streams on stdin far more often than I sort named files.
> 
> So what's been established is that 'sort' is useful for a text stream
> that already exists as a file or is the output of another process.

Indeed. And "another process" can just as easily be a human at the keyboard,
although we must keep in mind the primitive line-oriented editing facilities
of stdin (basically backspace and that's it).

 
> What hasn't been established is why how this works this has to influence
> the design of simple text-based dialogues, real ones where there will
> likely be an actual user tapping the keys in real time.

Obviously it doesn't, and as far as I can see, nobody has suggested that such
primitive facilities should be treated as the archetype of *user-oriented*
application programming. There are other kinds of programs than those aimed
primarily at direct use by users.

As I interpret what people have been saying in this thread, the claim is far
more modest:

- sort is designed for use in pipelines, as a typical Unix tool;

- the way to exit sort is the same way you exit pretty much everything
  in the Unix command line, using EOF (Ctrl-D);

- Unix admins and even Unix end users learn Ctrl-D just as Windows users
  learn ESC and Ctrl-Q and Alt-F4 and the other myriad standard ways to
  exit an application in the Windows world;

- as a Unix tool rather than a text-based application with a rich
  user-interface, it doesn't need verbose output, introduction messages, 
  help screens, and all the other bells and whistles;

- although there is a valid argument to be made that sort could be a little
  more user-friendly in interactive use without badly compromising its 
  primary purpose. But that's a matter of taste.


Besides, we know what the nirvana of user-interfaces should look like:

https://www.gnu.org/fun/jokes/ed-msg.html



> The only tenuous connection I can see, is that if 'sort' is run without
> any piped or redirected input, it will resort to the keyboard.

It doesn't "resort to the keyboard", that's just how stdin works.

If you have a car built to drive on roads, and you drive it up onto the lawn,
the car doesn't need a special mode that detects the missing road
and "resorts to driving on the lawn". It just happens. Stdin is like that.




> Even though that method is not user-friendly 

True enough. `sort` is not designed to be a end-user application, although it
can be used by the end-user.


> and hardly anyone ever uses it in that mode.

Translation: "I don't use it in that mode".


> So that same unfriendly technique should be the model for 
> text dialogues everywhere.

I'm pretty sure that nobody said that.




-- 
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