by pdntspa · 2y ago · 0 comments
Also, I don't know what it is with shell programmers (and I've worked for one) but bash syntax is similarly insane. I am so glad I've never had to write an init.d service because 20 years into my linux career I still can't read that shit. Like I can launch and fork a process in like 10 lines of C, but it's five pages of gobbledygook shell script?
I write C# daily but I'm not fine with powershell syntax. It seems harder than it should be.
Batch is not nearly as flexible as PoSH although the interpreter still boots faster so I use cmd.exe all the time.
At least it’s terse, which is good when you’re typing commands on the fly on the command line. PowerShell on the other hand is so unwieldy on the command line. Even the pervasive use of case slows down typing.
(Get-ChildItem -Filter '*.txt' | ForEach-Object { $_.Length } | Measure-Object -Sum).Sum
You can do ls *.txt | measure -Sum Length | % SumYou're not wrong. I think it's that way because of trying to increase readability. Best practice for Powershell cmdlet development is verb-noun.
Of course they throw that out the window with aliases.
Examples:
wget and curl both are aliases for invoke-webrequest
iex is an alias for "invoke-expression" - which lets you execute a string as powershell code in your same session (note: I originally wrote scriptblock, which was incorrect - otherwise something I wrote this week wouldn't work at all, due to change of scope). This ability gets me out of a lot of weird jams.
The other thing too which makes it so weird is that it is built on top of .Net. The overarching principle of Powershell is that it's your Windows swiss army knife. You can access .Net classes by loading the assemblies. I have on occasion built a small WinForms app in powershell. You can create and invoke COM objects (new-object cmdlet).
> But as a polyglot I am so sick of having to learn yet another syntax.
Personally, I try to avoid "language specific sugar" when I am writing sample scripts for people (I am in a customer facing role). But goddamn I love the shorthand way you can do a for loop in Powershell using the range operator:
1..100 | % {Write-Host $_}
> cmd.exe does everything I need to and batch is actually kind of flexible.
OK, so you haven't really gotten to know Powershell very well if you're saying things like this. lol
Scripting in batch files is like living in the dark ages. They are "kind of flexible" whereas Powershell is "very flexible, most of the time".
And that "most of the time" caveat is no longer there if you are on the latest powershell (which doesn't work with the ISE as ISE is 5.x only, and the way of the future is the universal PWSH). My biggest gripe was fixed I think in Powershell 7, which was manipulating files with grave marks in the name.
I build a lot of stuff in Powershell, as you can probably tell. Given all the interop stuff it has, once you know how to use it all, the point where it makes sense to build it in C# is farther down the line than you might think.
It writes impeccable code - but doesn't always get the question right. I've found most of the time, even when it gets the question wrong, it turns you onto the right path forward. Definitely has saved me a lot of time researching things.
Generative AI can do a lot of fun things, but we're talking about a but it does not belong anywhere near an interactive shell.
Yeah. At a certain point it is almost impossible to internalize that complexity.
As someone suggested...in the era of AI, this might not matter at all.