top | item 39459214

(no title)

cljacoby | 2 years ago

I also use cat this way, and for me the biggest reason is it just allows for a more intuitive left-to-right reading of any pipeline.

Things like this:

head -n 500 access.log | grep ...

head -n 500 <access.log | grep ...

Feel like you start with the filename, then go leftwards to the first operation, then start reading rightward again through the pipe. At least in my brain, it feels slightly more awkward.

discuss

order

didntcheck|2 years ago

I wish math notation and computer programming had just settled on postfix over prefix early on, it's so much more natural to read. Of course, we kind of get it with object oriented programming, some languages have UFCS [1], F# has that pipe operator etc.

It's funny, when learning programming, I think Haskell was the language that introduced me to the pattern of having a chain of operators processing a stream to build up a result (and I'd later cover it again in SICP), and I loved how clean it looked compared to imperative code. But I now find it one of the harder to read languages due to it all being prefix, whereas Java/Kotlin/C#/Javascript now all have stream constructs that use method calls, so read left-to-right, source-to-sink

And I'm reminded that I need to give Forth a proper go sometime

[1] https://en.wikipedia.org/wiki/Uniform_Function_Call_Syntax

lubutu|2 years ago

You can do...

  <access.log head -n 500 | grep ...
... though that's less familiar to many, I'm sure.

cljacoby|2 years ago

Neat, I didn't realize you could order it like that.

I'm realizing now another (and potentially stronger influence) is just years of muscle memory starting pipelines with cat.