Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

They had an opportunity to make a whole new, good, scripting language. And blew it spectacularly.


The decision to make the console output as the return value of a function alone almost destroys it for larger scripting projects. It’s a really bad decision and they could still fix it by adding some environment variable that disables this “feature” while staying compatible with old scripts.


This behavior? https://devblogs.microsoft.com/powershell/suppressing-return...

It seems like it might make some kind of sense, since it doesn't output directly to the console but rather to a pipe. Bash functions sort of work the same way since they don't have complex return values (aside from exit codes) other than the function's output stream.


Yeah, keep in mind that the output is a fully-fledged object, it is not the text you see. The text is generated by the PowerShell host if the returned object makes it back there and the host is set up to present that object to the user that way.

Take the following in PowerShell:

ls | sort DateTime -d

ls returns an array of objects, sort then sorts the array by each object’s DateTime field (and here I’m asking it to sort in descending order with -d). The point is that sort isn’t depending on any text output, so it works with any array of objects regardless of the command that returned them.

The other cool thing this enables is auto-complete awareness in the shell. If I typed:

ls | sort <Tab>

then the shell knows what makes sense in auto-completion here as ls has an actual return type and in this case it will give me a list of available fields that I can sort on.

For those unfamiliar: ls and sort here are shortened aliases to more wordy verb-noun commands. These (as well as a large bunch of others) are given to you by default.


Yeah, PowerShell is the only mainstream shell that behaves like the REPL environments from Xerox PARC workstations.

Structured data with direct access to any OS API, regardless how it is provided, .NET, COM or straight C like DLL.

UNIX world never had that, beyond trying to fit language repls as user shell, which on UNIX always feels like a leaky abstraction.


PREACH

But just so you are aware you can use the 'class' modifier To change this behavior.

It is one of the most fundamentally bizarre language design choices I have seen in my career


I have used classes too but this has all kinds of other weird behavior.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: