4 ms·
Another UNIX principle is that programs deal with text. PowerShell is huge violation of that principle. You can't easily write PowerShell command with C or Rust
by vbezhenar 11y ago
Another UNIX principle is that programs deal with text. PowerShell is huge violation of that principle. You can't easily write PowerShell command with C or Rust or Java, as far as I understand. Yet you can write command-line tool with any language and use it with combination of hundreds existing tools.
- wz1000 11y agoA solution to this might be a standardized object format, like JSON.
- vbezhenar 11y agoJSON doesn't support behaviour (methods). They are very useful for composing programs IMO.
- wz1000 11y agoBehaviour could be implemented by shell commands. That way, if you wanted to implement a method for a particular object, you could just write a binary/shell script/whatever that reads the object from stdin and writes its result to stdout
- masklinn 11y agoMethods are useful to organise and abstract programs, they're really quite bad at composition. Many functions operating on the same primitives is much more composable than small sets of functions operating on their own custom primitives.
- sudioStudio64 11y agoif the deserialization mapped to a system wide type system then the methods could be mapped in at that point.
- current_call 11y agoThen you'd need a JavaScript interpreter. Which would be terrible.
- icebraining 11y agoWell, it doesn't have to be JS specifically. In theory, it could even be a piece of machine code.
- chaz72 11y agoAnd a small number of tools for composing JSON.
- Slackwise 11y agoYAML seems more preferable, since it would be far more readable when STDOUT is the shell. Oh, and JSON is a functional subset of YAML, so you'd still be able to output as JSON and a YAML parser will read it.
- jsjohnst 11y agoExcept what about Dates? Or apps were floating point precision is important? Or needing to deal with very large integers? Also, have you thought about how large the output would be for ls as JSON? Think about the I/o usage if every time you invoked ls it had to do a deep walk of the file system to get all the possible data ls might output with all its command line arguments.
- sudioStudio64 11y agoPS will take the text output of any command line program and turn it into .Net strings that can then be manipulated like any other object. You can write PS cmdlets in C/C++, there is an SDK. It will also marshal COM objects into and out of the appropriate .Net types. When dealing with output from command line apps I usually take the time to parse out the data I want from the strings and turn them into strong types if I'm writing a script...If I'm just trying to get something done with a command prompt I just do whatever gets it done the fastest.
- cremno 11y ago>You can write PS cmdlets in C/C++, there is an SDK. Are you sure? AFAIK you have to use C++/CLI which isn't C++ and the official examples are either C# or VB.NET: https://code.msdn.microsoft.com/site/search?f[0].Type=Topic&f[0].Value=Windows%20PowerShell&f[0].Text=Windows%20PowerShell https://code.msdn.microsoft.com/site/search?f[0].Type=Topic&...
- sudioStudio64 11y agoIn the 2012 R2 time frame Jeff Snover said that they opened up cmdlet authoring to subsystem teams to use C++ to build cmdlets. Maybe they haven't released it yet? That may mean that you have to implement at least some part of it as a .Net class. That may mean that they are doing COM components that inherit certain interfaces...it may mean that they are doing PInvoke...to be honest I haven't looked into it. It may be that it's still internal. Huh. I should look that up.
- nailer 11y agoDo your own apps communicate via text? Eg, rather than use JSON for the REST APIs you write, do you use only strings? Text made sense because text was the universal format. Now we have JSON. In the Windows world .net objects are universal (though I'd prefer JSON).
- espadrine 11y agoI don't understand your point, since JSON is a textual format. Sure, the fact that Unix chose text meant they created a lot of different formats, some non-standard, but I don't see this being an issue, except for configuration purposes.
- nailer 11y agoDo you deal with the serialized JSON text directly, or run JSON.parse() and JSON.stringify() to turn your JSON into objects? Do you ever use regular expressions to parse unstructured text when using a Unix shell? Do you think 'grep' and thinking of a regex is more or less efficient that using 'where'?
- camperman 11y ago"or run JSON.parse() and JSON.stringify() to turn your JSON into objects?" By that time, the communication has already happened.
- nailer 11y agoWell the only point of serialising was communication, so I'd argue unwrapping a presentation layer format is included as part of communication.
- camperman 11y agoFair enough. I was coming at this from my current experience where a couple of different programs I have grab JSON from a server: the Python one puts it into an object, the bash script doesn't because I couldn't be bothered :)
- wumbernang 11y agoYou can. Half way through a powershell script you can switch to C#, VB, JavaScript if you want and implement a pipeline or shell out to a C++ program, talk to something over the network or even Cygwin if you really want.