Hacker News new | ask | show | jobs
by LelouBil 1276 days ago
I had to try PowerShell for a project.

It is soooo much better that bash.

Passing typed objects instead of only text, Typed functions, and the ability to use C# types/functions inline !

3 comments

To me it's about half way there. The things I like about it the least are the ones that are like bash ("I'd just like to interject for a moment, what you're referring to as Bash is in fact called POSIX shell").

A common argument in defense of its weirdness is that "shell scripting isn't like serious software development", but I don't understand that either.

I use shell scripts a good amount because "it's right there" is a strong argument, but in a lot of cases things that seem like they would be trivial take forever, are horribly hacky and leave me wishing I just had written a Python script right away instead.

I really don't get why people like shell scripts.

People like shell scripts because you have one interface: text

For example: you need to write an image to a USB stick. Python: pretty lengthy BASH: image > /dev/SDA

Both will do exactly the same, but one is a few lines of python the other just one line in bash.

Why a throwaway for this? Is this a gpt response?

Also it's not right. You need to do something like image.img <cat> /dev/sda

Why a throwaway? I am on my phone with no access to my real password. Don't get bothered by it?!

Did this look like a proper bash command to you?! Maybe that was some runable python code?!

File ending has nothing to do with its contents. Image.img could be an mp3.

Stop hairsplitting.

Not upset but I am touchy about gpt results. The ending wasn't the key part, the <cat> was the key part. I added img because that's the only image type I can think of that makes sense to write to sda in that way.

Why would anyone write an mp3 to a block device bit by bit

    dd if=<image> of=<output device> bs=<block size>
I use this whenever I need to bake an image to a USB stick.
Always append status=progress and conv=fdatasync Makes sure that the buffer is flushed to disk before finishing.
Of course. That's the right way to do it. I was pointing out that what was written isn't right in any situation and the smallest change to make it make sense would be adding <cat> in the middle

Turns out my answer was wrong too :D. Should have been <image.img cat >/dev/sda. Oh well

Now we only need it to start up at least 100 times faster than it does currently, and be available out of the box absolutely everywhere.

I have no use for it for these reasons alone.

  $ hyperfine -N 'bash -c ""' 'dash -c ""' 'pwsh -c ""'
  Benchmark 1: bash -c ""
    Time (mean ± σ):       2.2 ms ±   0.1 ms    [User: 1.8 ms, System: 0.4 ms]
    Range (min … max):     2.1 ms …   2.6 ms    1214 runs

  Benchmark 2: dash -c ""
    Time (mean ± σ):       0.6 ms ±   0.0 ms    [User: 0.5 ms, System: 0.1 ms]
    Range (min … max):     0.5 ms …   0.8 ms    4623 runs

  Benchmark 3: pwsh -c ""
    Time (mean ± σ):     278.5 ms ±  10.8 ms    [User: 267.6 ms, System: 64.9 ms]
    Range (min … max):   263.8 ms … 297.0 ms    10 runs

  Summary
    'dash -c ""' ran
      3.80 ± 0.23 times faster than 'bash -c ""'
    470.61 ± 31.00 times faster than 'pwsh -c ""'
And have core cmdlet features available in all supported versions.

For example, `Invoke-WebRequest` generates an error when you get a response by default with a 5xx status code, even if there's data in the response body. The switch to turn that off (`-SkipHttpErrorCheck`) wasn't added until ~7.2, so to support older Windows installations I don't have control over, I have to write it targeting the older version.

You don't find this out via the online documentation (unless you explicitly diff the call signature); only when it fails running on that Windows Server 2016 VM do you find out that, oh, it's only a supported parameter in newer versions of PowerShell.

And that's just a single example.

Did you make a typo when referencing a variable? Ha, let's silently initialize it to null without saying anything. Want to turn on strict mode to catch stuff like that? Better not put that line before the script-level parameter block, because fuck you. Great, that's sorted... ugh, now some type in some random function call doesn't explicitly match so the silent casting we were doing for you is now an error! How was the silent cast being done before? Fuck you for asking, we're never telling. Did you want to put some log / print statements in your functions? Have fun finding out why the function return value is suddenly an array!

As a shell scripting language for short, personal things, it's great. But for building anything bigger? Give me Python or C# or TypeScript or anything with better tooling around it.

Objects may be nice until they are not.

Personally, I'm of the opposite opinion.

I especially dislike the verbose syntax.