4 ms·
> it is perfectly possible to write clean, maintainable, and testable shell scripts. Possible? Maybe. Easy? No. Especially the “testable” part. The vast major
by HL33tibCe7 4y ago
> 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).
- jmmv 4y agoI 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.
- HL33tibCe7 4y agoI 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.
- fbdab103 4y agoBad 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.
- _dain_ 4y agoFirst, 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.
- waynesonfire 4y ago> 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/wg-quick/freebsd.bash https://github.com/WireGuard/wireguard-tools/blob/master/src...