News for hackers. Stuff that matters.
Re:Write Posix Shell by HL33tibCe7 on Saturday March 11, 2023 @10:42AM (#35109194)
> it is perfectly possible to write clean, maintainable, and testable shell scripts.

Possible? Maybe. Easy? No. Especially the “testable” part.

The vast majority of engineers do not know how to write clean shell, let alone testable shell. There’s a reason for this: it’s extremely difficult and non-obvious to do, and generally isn’t worth investing the time in learning (you can just use a different language instead: perhaps one with support for advanced features like… arrays…)

So sure, you can write your 500 line shell script and it may well end up being beautiful. But what happens in 5 years when someone who isn’t as enlightened as you has to maintain it?

(This all without mentioning the worst aspect of shell scripting: security. Good luck handling secrets without leaking them in one way or another).

Re:Write Posix Shell by jmmv on Saturday March 11, 2023 @10:50AM (#35109279)
I see your point, but what happens in your alternate world of having to maintain the 5000-line Python version 5 years down the line? You face the same issues you describe. The people that wrote the original beautiful code aren't there anymore, and whoever comes touching the code "messes it up". Most Python "scripts" I have had to deal with that had been around for a while were pretty terrible as well.
Re:Write Posix Shell by HL33tibCe7 on Saturday March 11, 2023 @10:58AM (#35109389)
I don’t think you do see my point: my point is that writing clean, testable, maintainable Python is both easier and a more widespread skill than writing equivalently clean, testable and maintainable shell. Both of these factors will mean that the Python remains maintainable for longer.
Re:Write Posix Shell by _dain_ on Saturday March 11, 2023 @11:38AM (#35109923)
First, I doubt that the SLOC conversion ratio between sh and Python is really as high as 10x.

Second, yes, I do think the 5000 line Python script would be more maintainable than than the 500 line sh script. I'd choose real types and data structures any day of the week.

Re:Write Posix Shell by fbdab103 on Saturday March 11, 2023 @11:01AM (#35109426)
Bad code is bad code, regardless of language. At least with Python, I more or less know all of the idioms and can at a glance understand what the flow of a program is trying to accomplish. Shell has a lot of esoteric voodoo syntax to replicate better string/path/array handling that is just a given in other languages.
Re:Write Posix Shell by waynesonfire on Saturday March 11, 2023 @11:14AM (#35109591)
> Possible? Maybe. Easy? No. Especially the “testable” part.

a testable shell script? Never seen one.

Thinking about scripts I've read in the past, I remember seeing Jason Donenfeld's bash script for wireguard-wg and thinking how productive and readable it was,

https://github.com/WireGuard/wireguard-tools/blob/master/src...