News for hackers. Stuff that matters.
Re:Write Posix Shell by hedora on Saturday March 11, 2023 @11:57AM (#35110165)
Python is untyped and untestable. The only way I’ve seen people use it is by importing whatever libraries were popular in whatever year they wrote it, so it’s also arcane.

Also, to understand someone else’s python, you have to read at least 10x more lines of line noise, so it somehow manages to be less maintainable than shell.

Concrete example: Every python code base I’ve encountered has some function named exec that poorly reimplements shell job control and argument passing. As the python code bases grow, they end up with more than one of these, all of which have different bugs.

I usually discover this about 6 hours after the script has been sent to me, since someone who has heard the words “supply chain vulnerability” locked down whatever machine I need to run the script on.

The last ten times this has happened (at multiple companies, with multiple teams) it ended up being faster to figure out what shell commands the python script wanted to invoke, port a few things to jq and then reimplement the rest in a mix of shell and perl.

The result is always 1-10% the lines of code of the python, and actually runs without downloading an entire python distribution, dependency manager, and hundreds of broken packages at runtime.

Re:Write Posix Shell by _dain_ on Saturday March 11, 2023 @12:40PM (#35110642)
>Python is untyped and untestable.

Completely untrue. You're conflating static typing with strong typing. And pytest is a great test framework.

And you're recommending shell for better typing and testability? The language where everything is a string and there are no proper arrays? You have to be trolling.

Re:Write Posix Shell by oweiler on Saturday March 11, 2023 @02:03PM (#35111450)
On top of that, fn in Bash can only return their status code. Yes, command substitution exists but is full of footguns.
Re:Write Posix Shell by hedora on Saturday March 11, 2023 @08:18PM (#35115167)
I’ve probably spent two weeks (80+ active hours) debugging stuff like ‘“” is not None’. At this point, I’d prefer a language with only string types to one that only checks types in production.

pytest is terrible, at least from how I’ve seen people use it. It hides the diagnostic error explaining why the test failed in a random place. Its output is not parseable. If you have a long running test that times out, then it buffers the stdout and stderr so you have to wait for the fallback test time out every. single. time.

Re:Write Posix Shell by Too on Sunday March 12, 2023 @03:52AM (#35117815)
You've got exactly same problem of undefined vs empty in sh (-n not being exact inverse of -z vs string comparision with != "", different behavior if -u is set, etc). Just check the stackoverflow answers on how to test if a bash string is empty or undefined and there isn't even consensus on what is the best way to do it.

Mypy has had strict Optional checking on as default since 2018, almost entirely eliminating any None-related errors, meaning it is actually stricter and safer than Java or other traditionally considered static languages in that regard, (bar any dynamic misuse in deserialization boundaries). Assuming you use mypy of course, but that's a given today imo, like using shellcheck is for sh.