... why would you ever use Unix tools to solve those sorts of problems?
Rob Pike: "Current Unix tools are weakened by the built-in concept of a line"
21–30 of 112 posts
Re: Rob Pike: "Current Unix tools are weakened by the built-in concept of a line"
#22Earlier quoted context omitted.
Not sure about the date of publication, but Rob developed these ideas in the early 80s, his Sam editor (that Ken Thompson still uses) is based on it.
offtopic: sam(and acme) sounds like an interesting method at first, but when you try it out, its really weird and slow to get stuff done. Its because for me, mouse is really inferior to keyboard to do the majority of the tasks. This is an except from coders at work: Seibel: Is there anything you would have done differently about learning to program? Do you have any regrets about the sort of path you took or do you wi…
I suspect ken spends most of his time thinking rather than typing, and I have found this to be true of most great hackers.
Other famous Sam users include Brian Kernighan, Bjarne Stroustrup(!) and Tom Duff. Kernighan writes at least as much English as code and I wonder how that affects his editor usage patterns, but I suspect that even when writing natural languages most time is best spent thinking (his writing style is very concise and clear, one could say similar to ken's code).
I think the obsession with saving keystrokes is very misguided, I still use editors like vi frequently, and having to think about what magic combination of commands to use to perform a task can be very distracting, is fun and feels good, like a tiny puzzle game built into your editor, but it doesn't help you write better code faster IMHO.
P.S.: Is interesting who has stuck with Sam and who moved to Acme (Dennis Ritchie switched to Acme, and most of the Go team Google besides ken use it too).
See also: http://sam.cat-v.org/
Re: Rob Pike: "Current Unix tools are weakened by the built-in concept of a line"
#23( RECORD_PATTERN=somepattern; my | pipe | line | whatever )
rather than
my -R somepattern | pipe -R somepattern | line -K somepattern | whatever -R somepattern
Re: Rob Pike: "Current Unix tools are weakened by the built-in concept of a line"
#24Possibly true, but we have perl, python, ruby to deal with those cases which all embed regex in a structural way. Occasionally you can just convert it to lines first as well and problem solved.
Re: Rob Pike: "Current Unix tools are weakened by the built-in concept of a line"
#25His example is poor, but the message is that the body of a record can cross line boundaries. While the UNIX tool chain is predicated on the concept line == record, this doesn't have to be the case. With a generic record level marshalling system the class of problems solved by composing command line tools together would be greatly expanded. What Pike describes is analogous to the RecordReader in Hadoop.
Re: Rob Pike: "Current Unix tools are weakened by the built-in concept of a line"
#26Some researchers at the University of Helsinki have studied the hell out of this problem, and even provided a useful tool that is available in many Unix distributions called "sgrep". http://www.cs.helsinki.fi/u/jjaakkol/sgrep.html
(It hides the GUI and gives it a more ed-like interface that you can easily script, but this is kind of a hack for Plan 9-nuts ;)
Re: Rob Pike: "Current Unix tools are weakened by the built-in concept of a line"
#27Earlier quoted context omitted.
Not sure about the date of publication, but Rob developed these ideas in the early 80s, his Sam editor (that Ken Thompson still uses) is based on it.
offtopic: sam(and acme) sounds like an interesting method at first, but when you try it out, its really weird and slow to get stuff done. Its because for me, mouse is really inferior to keyboard to do the majority of the tasks. This is an except from coders at work: Seibel: Is there anything you would have done differently about learning to program? Do you have any regrets about the sort of path you took or do you wi…
You say it sounds like an interesting method at first, but then you try it out and it's weird and slow. How much of a try did you give these editors? In the same way that a new Vim user will basically use the arrow keys, "i", ":w", and ":q" and nothing else, a new user to Sam or Acme can very easily miss a lot of the power.
The Sam language is pretty powerful. For instance, you can use the "X/regexp/ command" form to apply a command over every file whose filename matches the regex, so you can (for instance) make a change to every .c file while leaving README alone. Acme lets you use the same command language, but also lets you execute other arbitrary commands by simply typing them and mid-clicking on them--yes, I know Vi lets you do something similar, but with Acme you'll typically build up a "guide" file, full of convenient commands that you just sweep over with the middle mouse button and release to execute. Acme also presents files in a sort of tiling window manager fashion that makes it one of the most convenient editors I've used. I'll frequently have up to about 50 files open, which in Emacs or Vi would drive me nuts trying to constantly switch around them or split the screen into one or two panels (oh boy, C-x b!). In Acme, I can always see the titles of the individual buffers, and if I need to see into the file I can with a mouse click or two expand the buffer into a convenient size.
I think one change that could really have a big impact is making the ESC key switch back to the command window; this makes things a lot more familiar for Vi-heads, and it makes sense to eliminate a mouse movement for something that simple and frequent.
That ended up a lot longer than I intended, but I wanted to try and share a little bit of my thoughts on Acme and Sam, and encourage others to give them a more thorough try. At this point, I use vi for quick edits, but when I have to write a lot or make a lot of changes, I bring out Acme. When I'm stuck on a strange system that's not my own, I have a tarball of an old version of Sam which, with a little tweaking, has compiled on every version of Unix I've had to use.
Re: Rob Pike: "Current Unix tools are weakened by the built-in concept of a line"
#28People praise perl, sed, awk, cut, etc. for being good at text processing. But the only reason they need these text-processing tools for pipelines is because they are trying to recover structure from the data that was already present before the previous stage of the pipeline threw that structure away by dumping it to flat text!
Text is obviously a convenient way for humans to view a program's output, so clearly it's useful that all Unix programs (ls, ps, etc) can dump their output as text. But there's no need to dump to text until the output is being sent to a human. If you're piping "ls | grep" there is no reason for "ls" to dump to text and "grep" to parse it back from text, especially since "grep" doesn't know anything about the format of ls's output. It would be way more convenient if you could say something like:
ls | grep 'file.size > 1M'
But the only way to do this today is to parse ls's output first. There would be no reason for this if ls could send structured data to grep.What I'm describing is similar to Monad, Microsoft's next-gen shell. AIUI it can send .NET objects between processes instead of flat text. But IMO it's too imposing to mandate a single object representation like .NET objects.
I'm experimenting with the idea of letting people specify the output of command-line utilities as a Protocol Buffer schema, for example:
message DirectoryEntry {
optional uint64 inode = 1;
optional string name = 2;
optional uint64 size = 3;
// etc.
}
I think this could be a compelling way of making the next generation of usability in command-line pipelines, by saving people from having to write ad-hoc parsers all the time.Re: Rob Pike: "Current Unix tools are weakened by the built-in concept of a line"
#29Re: Rob Pike: "Current Unix tools are weakened by the built-in concept of a line"
#30Possibly true, but we have perl, python, ruby to deal with those cases which all embed regex in a structural way. Occasionally you can just convert it to lines first as well and problem solved.
I don't think they really give you a structural way to use regexes; more of a procedural way, where you can embed regexes within explicit loops that iterate over lines, matching and updating state-variables as you go. Unlike regexes, which are declarative and abstract away the details of the match algorithm and its internal match-progress variables, you are explicitly maintaining the match state there. I find myself…
Something like (perl):
&visit_matches(
{ ' +' => sub { $x += length( $1); },
'#+' => sub { print $1, ' at ' $y, ',', $x'; $x += length( $1); },
'\n' => sub { $y++; }
});(not an exact match to the pseudo-awk, but enough to get the idea)