by Brian_K_White · 4y ago · 0 comments
Any particular version of Python is a saner choice, if you could pick one and freeze it retroactively for the last 20 years and for at least the next 20. But that is not how Python works. Python breaks every 11 minutes.
I would not write anything in Python that I cared the slightest bit about longevity or portability.
Maybe if we made a subset of python, locked down the syntax and feature set, discouraged any use of plugins or libraries in any fancy way that relies on any kind of repository or package manager system, and gave it a new name to distinguish it from normal python, maybe that would be an ok replacement for any of the shells.
But that is not happeing and don't even try to pretend like it could.
Are there any other languages with the same stability that would also fill this niche?
A bit of a shame that it's seen as an anachronism to many. Perl soon rubs off on you and becomes a delight.
Also, I’ve been using various lisps (elisp in emacs org-mode and Common Lisp) and they both can be written in ways that will probably last a long time.
Using awk as a general purpose language means slightly bending it out of shape, by mostly ignoring the main section (which runs once per selected record of input) and writing your entire program in a big END{} section.
BUT
* It's installed everywhere and has been forever just like sh
* A 20 year old awk script from hpux or something, works in todays gawk, just like sh.
* Unlike sh, the language is more like a normal generic language than, making it more readable and less arcane for non-trivial jobs.
For example, bash has a handy substitute feature, in the form of a brace expansion. ${FOO//a/b}
Awk has an actual sub() or gsub() function.
A lot of things in bash require tricks essentially abusing various fancy brace expansions and messing with IFS to hijack the line parser into doing things there is no explicit command for, especially if you're avoiding external commands. IE you're not simply writing code that does what it says, you're running a bash interpreter in your head and manipulating strings so that when they are expanded and resolved, they mean something to the the parser and results in the parser doing something more useful. It's like your always writing code that writes code, instead of just writing code.
External dependencies is another whole point too. Shells main explicit job is to run other programs. You actually have to work pretty hard not to run an external binary by accident, ie you have know which commands are built in and which are executables. In awk or anything else, you have to go out of your way to exec() or system().
All of my Python 2.6-2.7 scripts haven't been touched in 10 years in production and they aren't likely to ever be updated. I actually now refuse to write new Python that isn't compatible with both 2&3 for this reason. Python3 refuses to stabilize.
If you mean my software I mentioned if something breaks I'm still required to fix it. I just doubt that will happen at this point and have other tasks to do.
Python 2 went away in macOS. Bash still exists.
There's still a macOS installer for the latest release of Python2.7 (4/20/2020).
[0] Sunsetting Python 2. https://www.python.org/doc/sunset-python-2/
`/usr/bin/python` invokes Python 2.7.18 on my just-bought Macbook Pro 14 running MacOS 12.2. Maybe that's because I installed the Xcode command line tools?
[0] https://www.macrumors.com/2022/01/28/apple-removing-python-2...