tlehman.blog >

Jeffrey Snover was right

39 page views   |   434 words   |  
Jeffrey Snover is the inventor of PowerShell, a command line interface for Windows. What made PowerShell different from all the other shells that are used on Unix? PowerShell builds pipelines between processes that pass structured objects between them. As an example:

Get-Process | Where-Object { $_.CPU -gt 10 } | Select-Object ProcessName, CPU, ID

The Get-Process cmdlet (commandlet) passes structured objects, with a .CPU attribute to the next process, which reaches into these structured objects to do filtering (-gt 10 means 'greater than 10'). Then Select-Object takes the subset of process objects that were filtered by Where-Object and reaches into those objects, pulling out ProcessName, CPU and ID to display.

This is different from the Unix Philosophy, which Douglas McIlroy described like this:
This is the Unix philosophy: write programs that do one thing and do it well. Write programs to work together. Write programs that handle text streams, because that is a universal interface.

So Unix is oriented around flat text files. Text encoded as ASCII or UTF-8 (which retains a backward compatibility with ASCII, so that old text files don't need to be re-encoded).

This long-term stability of text files as a store of data was foretold by Neal Stephenson in 1999, when he wrote in his essay, In the Beginning Was the Command Line:
ASCII text files, in other words, are telegrams, and as such they have no typographical frills. But for the same reason they are eternal, because the code never changes, and universal, because every text editing and word processing software ever written knows about this code.

That universality and immortality is what makes text files such a stable foundation for data interchange. So what changed? The discovery of JSON. JSON puts structured objects into these eternal text files. It's true that JSON is only one of many object serialization formats, but JSON's strength is in the standardization of JavaScript. It has the benefit of text files' universality and immortality, but it also gives the benefits of structured object passing, something which PowerShell is built on.

There is a tool called jq which is built in the full spirit of the Unix-philosophy, and it allows for fast JSON parsing in a Unix command line environment like bash or zsh. Paired with a new tool called jc, Unix command lines can now convert common commands' text outputs into a structured JSON object, and then use jq to reach into those objects. From the combinatorial chaos of the unstructured unix unicode soup emerges the Apollonian Object Orientedness of Snover's PowerShell. He was right all along.

#programming #shells #unix #os