6 ms·
I made a Bash script for HN, and while I’m the furthest thing from an expert in Bash (I’m a newb), I was impressed by a contribution made with a port of the scr
by rasengan 7y ago
I made a Bash script for HN, and while I’m the furthest thing from an expert in Bash (I’m a newb), I was impressed by a contribution made with a port of the script to Powershell[1]. You can see the same script compared in Bash, Powershell and Python!
Prior to this I had never really explored PS, but it is definitely cool
Shameless Plug:
[1] https://github.com/realrasengan/autobahn https://github.com/realrasengan/autobahn
- GordonS 7y agoThanks for posting this, it's interesting to see the same problem solved in 3 languages. I use Bash for all my scripting needs, on both Windows and Linux - I just can't get over my dislike of Powershell's verbose syntax and Pascal-Snake-Case naming! But some things are difficult or finicky in Bash; maybe I should stop putting off learning Python...
- gabrielsroka 7y agoPowerShell commands are not case sensitive. Commands use <Verb>-<Adjective><Noun> structure, for example Get-ADUser gets an AD user. Once you learn that, it's easy to know that the equivalent command for AzureAD is Get-AzureADUser. It did take me a while to get used to it, but it does make sense, and it makes it easier to learn/remember commands.
- GordonS 7y agoI know about the lack of case sensitivity, but in idiomatic Powershell, it's Pascal-Kebab-Case. If I use a language, almost everyone else's code is going to be idiomatic, so I would write idiomatic code too.
- majkinetor 7y agoThats silly. You can equally complain about short vs long parameter names with most CLI tools (- vs --). You also have tools for that just write short and use Expand-Alias
- GordonS 7y agoWell... yes, I suppose it is a bit silly! I've really tried to like it, but I just can't get past it. It's just my personal preference, but I've come across quite a few others who dislike the naming of Powershell commands too - seems to be a real love/hate kind of thing.
- majkinetor 7y agoYou should get over that trivial reason really. You are missiong out a lot.
- theamk 7y agoThis seems pretty unfair to bash - bash version is way longer than needed, both because it does more (more fields, difference tracking) and because it is written very vebosely (very long prefixes on each var, using multiple calls instead of single “read” command) I really dislike those comparisons where one side wins not because the language is better, but because it does much less.
- rasengan 7y agoI agree, and I see that you posted a better comparison with hn.sh! Thank you so much theamk!
- gabrielsroka 7y agoThanks rasengan. I've been using PowerShell for about 5 years now. I was trying to learn Bash, but I found too limiting -- it was like going backwards. So, I started learning Python. You'll notice that the PowerShell and Python versions are very similar.
- theamk 7y agoYes, because they do much less than the shell version Here is a shell version which does the same thing as python, it is much smaller as well: https://github.com/realrasengan/autobahn/pull/8/files#diff-6cd37e45d3c074636991849465b11a83 https://github.com/realrasengan/autobahn/pull/8/files#diff-6...
- gabrielsroka 7y agoIn fairness, when I ported the Bash version to PowerShell and then Python, the Bash version was much shorter. rasengan later added a lot of functionality to the Bash version. And the point was to demonstrate some of the functionality in a short example, not to be a line-by-line port. I find it's easier to learn a new language by looking at a short example. The rest is left as an exercise to the reader.
- rasengan 7y agoThank you gabrielsroka!