The "loop and a half"

bartc bc at freeuk.com
Sat Oct 7 08:06:23 EDT 2017


On 07/10/2017 02:46, Steve D'Aprano wrote:
> On Sat, 7 Oct 2017 06:18 am, bartc wrote:
> 
>> For sort, there is no real need. You use a text editor to create your
>> data. Then use existing file-based sort.
> 
> What you mean is, *you* see no need for sorting interactively, or sorting as
> part of a pipeline of functions. That speaks more of your lack of imagination
> and closed-mindedness than any real lack.

Where did I say that?

The 'existing file-based sort' works from files and pipes.

It's capturing the data to start with that it would be ludicrous to do 
interactively using such a crude interface.

> Personally, if I have a few (say, a dozen or so) lines I want sorted, it is
> much easier to:
> 
> - select text from whatever application I'm using;
> 
> - bring up a terminal (I almost always have one already open);
> 
> - type `sort ENTER`;
> 
> - middle-click to paste the lines;
> 
> - type Ctrl-D;
> 
> - select the output lines;
> 
> - paste back into the original application;


That's not entering the data interactively (such as typing 'sort' then 
it sits silently recording lines of text (you hope) until it sees EOF). 
You say the lines already exist in a text editor. Exactly what I said; 
you start with text that has already been entered or generated by other 
means.

However it does seem to expose a flaw in the ability of command line 
tools to work with non-command line tools.

So I have to copy 33,000 lines from a document, get to the terminal 
(keeping that document open because I'm not done with it), start 'sort', 
and paste those 33,000 lines into the console, then type Ctrl-D. Which 
then promptly prints the newly sorted 33,000 lines onto the console. 
Then you have to select those 33,000 lines (not easy as you now have 
find the midpoint of 66,000 lines of output), copy it, and paste it back 
into the app.

Put that way, it doesn't sound very sophisticated does it?

(Now I expect you're going to bombard with workarounds to fix all those 
issues.)

> (seven steps)
> 
> 
> versus:

<snip long sequence designed to make Bart look an idiot>

That's not what I meant at all, which is about creating the data from 
scratch. Here, the data STILL already magically exists somewhere!

Is it possible that you guys have never had to create anything original?

(How would /I/ sort a block of text in my editor? There's no built-in 
function, so using your approach:

  * Select the block

  * Ctrl KWfileEnter to write it to 'file'

  * Elsewhere, sort <file >file2

  * Back in editor, Ctrl KY Ctrl KRfile2Enter to delete then insert file2

Only four steps? Something went amiss in your analysis I think. And even 
these could be simplified by Using Ctrl KS and Ctrl KL to use a 
predefined clipboard-like filename for the intermediate.

However, how hard would it for the editor to do its own sorting? Not 
very, as it turns out, only half a dozen lines of code (see below after 
sig). Now the sequence is:

   * Select the block

   * Ctrl KH

How many steps did you have, seven?)

> I forget... it is "work harder, not smarter"? Being inefficient is a good
> thing, right?

Okay....

-- 
bartc

--------------------------------------------------
proc cmd_ctrlkh <"med:*ck*ch "> (td) =
     if td.blockstart then
         isort(td.text[td.blockstart..td.blockend])
         pageupdate(td)
     fi
end



More information about the Python-list mailing list