3 ms·
What if there was a less cryptic way to have mandatory arguments, something harder to get wrong, like param( [parameter(mandatory)] $name ) "Hello,
by IdiotSavage 2mo ago
What if there was a less cryptic way to have mandatory arguments, something harder to get wrong, like
param(
[parameter(mandatory)] $name
)
"Hello, $name!"
And then:
$ ./script.ps1 Dave
Hello, Dave!
$ ./script.ps1 -name Dave
Hello, Dave!
$ ./script.ps1
cmdlet script.ps1 at command pipeline position 1
Supply values for the following parameters:
name: <cursor here>
Or non interactively:
$ pwsh -nonint ./script.ps1
script.ps1: Cannot process command because of one or more missing mandatory parameters: name.
- refp 2mo agoDUDE! I wrote my first real `.ps1` the other day for auto-installing all dependencies needed to run a `gitea`-runner on windows for windows builds; powershell - felt like the lover I never had. And the documentation in readable comments at the top that just.. generates usable docs? Damn, damn, damn. There is a part of me that low-key wanna try that as my daily driver for a week or two. But with that said, I'm a zsh vi-mode guy - always have been, always will be.. but I'd happily take powershell on a romantic getaway every once in a while!
- rezonant 2mo agoAn attempt was made, but just run `help get-item` in powershell and tell me whether it sparks you with joy.
- delta_p_delta_x 2mo agoPowerShell needs to become more ubiquitous. There are so many things about it that once considered in greater detail make so much sense. Parameter setup, typing, and naming. Flow control. Object-oriented scripting. Built-in parsing for recursive data types like JSON, HTML, XML. And in my opinion, the most slept-on: the fact it runs on the CLR and direct access to .NET objects and types which means access to P/Invoke and thence the Windows API. One can write business logic in the fast language and write a nice CLI wrapper around that in the natural shell language, and not worry about painful FFI unlike everyone else trying to fit Python or Bash into whatever world they're using. The typical counter to this will be: PowerShell is verbose, PowerShell used `curl` as an alias to Invoke-WebRequest instead of the Real Thing™. Neither are real arguments.
- deleted 2mo ago[deleted]
- embedding-shape 2mo agoI'm curious, have any good examples of projects in the ~1K LOC range of PowerShell, so I could get a taste for how something like that would look like? Beyond that I tend to go for "real" programming languages, or just start with Babashka, but still curious to see projects other PowerShell fans would consider "well written/designed" :)
- iLemming 2mo agoIt never gets old - the number of times I have to roll my eyes and chuckle whenever someone "shares bash tricks" (like the OP) or says stuff like "powershell needs to become more ubiquitous" on HN. Seriously, have you folks not been vexed sufficiently with these things? Both bash/zsh and powershell are enormously frustrating and quirky in real, practical tasks. babashka in comparison is so much more pragmatic, simple and straightforward. I really don't want to become an expert in whatever - be that bash, powershell or anything else, I just want to get the shit done, I don't want to learn "tricks" and "magic", I just want to be able to close my laptop at 5PM and stop thinking about work. How the heck have we normalized "intellectual complexity" instead of "stupid simplicity", I still don't get it.
- crabbone 2mo agoPowerShell is a bad choice for the system shell because it's too complex. I'm not trying to justify all the quirks of Unix Shell, but minimalism is a very important feature of such a tool. Another important feature of a tool like this is the ability to tolerate errors: I can't imagine a Linux today that would be able to even boot if the shell was extra pedantic about errors. A lot of mostly irrelevant things routinely fail on boot and during normal operation. Stamping them all out is an arduous... well, basically, an impossible task for practical purposes where releases are expected to come on time, where users may manipulate configuration in gazzilions of unpredictable ways. PowerShell is just another language in the same box with Python, Perl, Ruby and many like that. It's not a good language, if you decided to reach for that box. Probably not the worst either. System shell, however, isn't meant for writing entire applications. Writing applications with elaborate command-line interface should be left to languages that can properly address this problem. PowerShell is trying to be there, but it doesn't hold a candle to its "older brothers" who can, indeed, design a very robust command-line interface, often using a dedicated library for it. PowerShell appeals to the novice crowd who are very enthusiastic about automatic checks in their code: the benefits are on the surface, the downsides are difficult to assess. This is in line with other Microsoft software products / languages which target novice programmers by implementing as many as possible of the highly-advertised features without regard to the overall usefulness of the product (think about C# or MS Office suit etc.)
- kunley 2mo agoWell said, esp. the last paragraph about the Microsoft strategy.
- garethrowlands 2mo ago> System shell, however, isn't meant for writing entire applications. Programmable shells are, in fact, for programming. That posix shell syntax makes it impractical for meaningfully large scripts is something you just accept. And, realistically, it is something you have to accept. Minimalism isn't why posix shell syntax is bad. For example, awk and jq are minimal but don't make the same mistakes. Powershell was never designed to be your system shell (Windows doesn't really rely on one) but the main reason it can't be the shell is startup time, which rules it out of wrapper scripts. Its having lots of features might contribute to that but it's not the problem per se (being built on .net is the reason - that and startup time not really mattering on windows). Its lacking the syntax problems of posix shells is very much not a problem. Powershell's error handling is just fine, by the way. The startup time of even pwsh is too slow to be usable in many scenarios. PowerShell's not going to be the system shell on your *nix box but it wasn't designed to be. But your posix shell isn't the system shell because it's better. It's pretty much the ultimate expression of worse is better. That's why there's an industry of alternatives without the faults, such as oil, elvish, fish, nushell. And why awk is so popular.