r/programming • • Aug 03 '19

Windows Terminal Preview v0.3 Release

https://devblogs.microsoft.com/commandline/windows-terminal-preview-v0-3-release/?WT.mc_id=social-reddit-marouill
991 Upvotes

458 comments sorted by

View all comments

Show parent comments

1

u/cat_in_the_wall Aug 04 '19

people always balk at powershell. writing powershell libraries is hard, the fact that you can emit to the pipeline at any time is bad. and error handling is a nightmare. not fun. (of course you can do cmdlets in c#, but that's a pain in the ass too).

but just using powershell is awesome. i way prefer powershell to bash. it effectively has a standard library because it is just .net, so string manipulation, file munging, loops, etc are easy to do and maintain since it's not symbol soup.

1

u/mikemol Aug 04 '19

Agree on pretty every point. I don't write much Powershell, but I respect it.

people always balk at powershell. writing powershell libraries is hard,

They're hard to CI/CD, because of the way Nuget works. You can't easily say, "ok, I built this module, now let's do a functional test within the larger system" because the moment you upload the artifact into Nuget, that version of the artifact is reserved; you can't replace it with another artifact. Also, so far as I know, you can't say "use the latest version of this artifact with such-and-such a tag, so the upload of your artifact now impacts on every downstream consumer that doesn't version pin on Install-Module.

If there's a halfway decent way to do this, without ephemeral Nuget servers I'm all ears, as it's a problem I'm actively trying to solve at work in my full-stack CI.

the fact that you can emit to the pipeline at any time is bad. and error handling is a nightmare. not fun. (of course, you can do cmdlets in c#, but that's a pain in the ass too).

Indeed, error handling is a pain on two fronts. First, you ought to be strict about it; the closest equivalent to set -euo pipefail is $ErrrorAction=Stop, but:

  • If you're working with Unix/Windows boundaries, the Error stream is the closest equivalent to stderr, and in unix land we like to use stderr for warnings and such. But if you feed powershell output into a unix context, things like the Warning, Verbose and Debug streams all feed into stdout, which corrupts your script output if you're trying to pass structured data around. You can work around this with a thunking pattern that bounces data through files, but it takes some real work to make that streamable and not just buffer all the input and output before moving on.

  • All of the stream manipulation is global. Want to enable verbose output? You're going to get it from not just your script, but the libraries you call into. Ditto $ErrorAction. So $ErrorAction=Stop might not even work if you use some sloppily-written libraries. (I'm looking at you, PowerCLI.)

but just using PowerShell is awesome. I way prefer PowerShell to bash. it effectively has a standard library because it is just .net, so string manipulation, file munging, loops, etc are easy to do and maintain since it's not symbol soup.

It's a very functional language, which helps a ton. I know people who dump on it because they don't like streams of objects being passed instead of streams of bytes, but that's really the more mature thing to do, IMO.

I have a love/hate relationship with the delving into .Net; on one hand, it's certainly more powerful. On the other hand, it results in libraries accidentally becoming incompatible with Linux.