by jpk · 9y ago · 0 comments
I feel like PowerShell is a step forward in the sense that it's a new thing with a more consistent design than the cobbled, creaky Unix environments we've become accustomed to. But at the same time I feel like it throws away one of the most intuitive aspects of the Unix interactive shells (character streams).
That's because you can't be both! The shell wants to be both an API and a user interface, and these are two goals that are fundamentally at odds. An API should be structured, strongly-typed, unforgiving; a UI should be discoverable, intuitive and unconstrained by the needs for automation or programmability. Programmers are stuck in the idea that a command-line shell running in a terminal emulator (emulating hardware from the 70's) is the pinnacle of interaction design, which is extremely sad.
% ls --libxo json
{"__version": "1", "file-information": {"directory":[{"entry": [{"name":"bar"}, {"name":"foo"}]}]}
}
% ls --libxo xml
<file-information __version="1"><directory><entry><name>bar</name></entry><entry><name>foo</name></entry></directory></file-information>Is it not reasonable to think of objects as having a description of some kind. Think of URLs, for example.
find -iname '*.c'
could emit file:// URLs rather than just filenames. Then anything can unambiguously understand the format of the output.Sure, everything can be made into strings at some point, but I've very rarely felt the need to do so in PowerShell (and regularly see on Stack Overflow that it only leads into problems down the (pipe)line if people try).
That's one of the main downsides of object-pipeline systems; in UNIX you can stop and serialise a pipeline to a file, then unserialise later. But you can't do this with object pipelines in Powershell because the objects have to be "live".