Hacker News new | ask | show | jobs
by papichulo2023 1023 days ago
Community refuses to admit that powershell is much better alternative to bash/python combo and here we are stuck in this mess.CI/CD scripts spaguetti is usually the most unstable piece of code in a company.
5 comments

> Community refuses to admit that powershell is much better alternative to bash/python combo

Because its not.

Powershell is very nice as a glue language for .NET components, and its better as a general purpose shell/scripting language than the old DOS-inspired Windows Command Prompt, for sure.

I think it’s better as a shell and scripting language than string parsing in unix shells too.
I'm not going to defend my opinion on powershell, because it's indefensible and arbitrary.

I just can't stand title case, and Microsoft/.net absolutely love it. Everything in power shell is DoSomethingLikeThis.

Powershell is a great piece of tech that I just can't use because I'm old and grumpy and like snake or kebob casing.

I've never tried it on Linux though, so maybe it's different there?

In this case, you might be glad to learn that PowerShell is case-insensitive, even for CLR methods.
I greatly dislike case-insensitivity. It's a source of many problems for users and implementors.

For implementors case-insensitivity means the need for full Unicode support is urgent, while Unicode canonical equivalence does not often make the need for full Unicode support urgent. In practice one often sees case-insensitivity for ASCII, and later when full Unicode support is added you either have to have a backwards compatibility break or new functions/operators/whatever to support Unicode case insensitivity.

For users case-insensitivity can be surprising.

For code reviewers having to constantly be on the lookup for accidental symbol aliasing via case insensitivity is a real pain.

Just say no to case insensitivity.

Are underscores/dashes coalesced out too?
There are aliases, you can name things with a letter if you want. There are even good ones OTB.
Most builtins are aliased:

    Get-ChildItem == gci
Yeah agreed, especially now that PowerShell is available cross-platform.

Nushell[1] also seems like a promising alternative, but I haven’t had a chance to play with it yet.

[1]: https://www.nushell.sh/

Why does it have to be bash+python? I'm finding myself using node.js scripts glued together by bash ones these days unless I'm working on a lot of data. Doing that means you can work with json natively.
`json.loads` in Python exists, and Python does the intuitive thing when you do `{"a": 1} == {"a": 1}`, at least for most purposes (you want the other option? `is` is right there!). Stuff like argparse is not the easiest thing to use but it's in the standard library and relatively easy to use as well.

Not going to outright say that node.js scripts are the worst thing ever (they're not), but out-of-the-box Python is totally underrated (except on MacOS where `urllib` fails with some opaque errors untill you run some random script to deal with certs)

I haven't had a great experience dealing with JSON in Python, but maybe I'm doing it wrong. What would be the Python equivalent of this JS code?

    JSON.parse(<data>).foo?.[0]?.bar
Basically just return the `bar` field of the the first element of `foo`, or None/undefined if it doesn't exist.
Assuming <data> will be a key-value-object aka dict, it would be something like this:

    import json
    data = json.loads('<data>')
    bar = None
    if foo:=data.get('foo'):
        bar = foo[0].bar    
    print(bar)
    
If you can't be sure to get a dict, another type-check would be necessary. If you read from a file or file-like-object (like sys.stdin), json.load should be used.
I love nodejs, it's my go-to language for server side stuff.

Even with that bias though, I have to admit that it's awful for typical command line script stuff.

Dealing with async and streams and stuff for parsing csv files is miserable (I just wrote some stuff to parse and process hundreds of gigs of files in node, and it wasn't fun).

Python is the right tool for that job IMHO.

Also, weirdly, maybe golang? I just came across this [1] and it has one of my eyebrows cocked.

[1] https://bitfieldconsulting.com/golang/scripting

Ruby is the clear answer here. The fact that more people don't use it for this purpose (its intended purpose!) is a travesty.
Any not-designed-specifically-for-shell language will suck for shell, more or less. Ruby, python, node, whatever, they all have the same problem - you write stuff too much and care about stuff you shouldn't care while in shell.
You're probably right. I just wish there was an easier way to handle json on the command line that didn't turn into its own dsl. The golang scripting seems interesting, might be what motivates me to learn the language.
Apparently, the old community need to literary die with their old habits for new to take place. There is no amount of good argumentation that can be fruitful here. And there is tone of it, pwsh is simply on another level then existing combos.
Has PowerShell learned how to pipe a byte stream without corrupting it?

https://stackoverflow.com/questions/33936074/decode-powershe...