The "loop and a half"

Steve D'Aprano steve+python at pearwood.info
Sat Oct 7 12:28:06 EDT 2017


On Sun, 8 Oct 2017 01:15 am, bartc wrote:

> On 07/10/2017 14:19, Steve D'Aprano wrote:
>> On Sat, 7 Oct 2017 11:06 pm, bartc wrote:
> 
>>> So I have to copy 33,000 lines from a document,
>> 
>> Don't be daft. Nobody says that stdin is a sufficient interface for a
>> heavy-weight task like that. With 33000 lines of text, I absolutely would
>> save them to a permanent file on disk, because I wouldn't want to risk
>> having the application crash or the power go off just as I've typed line
>> 32999 and lose the lot.
> 
> You're missing something I think. The 33K lines already exist elsewhere,
> and have been copied to the clipboard. So you won't lose anything if the
> power goes off, assuming the original are secure.

If I have the 33K lines in a file already, why would I copy them and paste
them into stdin (possibly overflowing the input buffer in the terminal) when
I can just call sort on the file?

I can even sort in place:

    sort -o filename filename

You seem to have decided that it is our position that the one and only
acceptable way to use the sort command is to launch it with no options, then
laboriously type (or copy and paste) all the lines into stdin.

We're not idiots. We have many options, and we use the one which is most
appropriate for the task at hand.


>> [...]
>>> Put that way, it doesn't sound very sophisticated does it?
>> 
>> Nobody said it was sophisticated. That's the whole point: having sort read
>> from stdin as you type into the terminal is the LEAST sophisticated,
>> simplest, most bare-bones, basic technique that works.
> 
> You do remember this was about using programs /like/ sort as a model for
> writing true interactive scrolling text apps?

I don't remember any such thing. I remember you *claiming* that, but if anyone
actually did make that claim, I haven't seen it.

There are reasons why sort defaults to not providing a richer UI. Its not
intended as a "Sort Stuff App". It is designed to be used in Unix command
pipelines, where an introductory message would be a nuisance.

sort *could* detect when it is reading from stdin interactively and give an
introductory message. I already said this. The fact that it doesn't is a
matter of the personal taste of the author, who presumably doesn't think it
is necessary. Simplicity is itself a virtue, although not necessarily to
beginners.



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