Is there any non-shell scripting language that makes it as easy as shell to run external commands, redirect I/O etc.? I don't know of any. (Perhaps that is the very definition of a shell.)
I think a good way of doing this would be to make a shell that has more expressive power and a clearer syntax.
Would Scsh count?
I've got 20 year old python scripts the have been upgraded over the years that are still maintainable, easy to read and do the job just fine.
Take good old fizzbuzz. Want to write it clear and simple in Perl? No problem:
for (my $n = 1; $n <= 100; ++$n) {
if ($n % 15 == 0) { print "fizzbuzz\n"; }
elsif ($n % 3 == 0) { print "fizz\n"; }
elsif ($n % 5 == 0) { print "buzz\n"; }
else { print "$n\n" };
}
Want to get clever and complex in Python? Here you go: def fizzbuzz(n, *args):
cur = ['' for x in range(1,n+1)]
for m, postfix in args:
cur = [y+postfix if x%m==0 else y for x, y in zip(range(1,n+1), cur)]
cur = [str(x) if y == '' else y for x, y in zip(range(1,n+1), cur)]
return cur
print("\n".join(fizzbuzz(100, (3, 'fizz'), (5, 'buzz'))))
Of course you could do an unclear and overly clever Perl version, too, or a clear and simple Python version. for (1..100) {
if (not $_ % 15) { say 'FizzBuzz' }
elsif (not $_ % 3) { say 'Fizz' }
elsif (not $_ % 5) { say 'Buzz' }
else { say }
}
Just saying say "foo";
was equivalent to print "foo", "\n";Perl obviously even lets experts shoot themselves in the foot on the simplest code, see the fizzbuzz above me, While a beginner would never write the complex python version that was shown, not even by accident.
An example of a langauge at the extreme other end of the spectrum would probably be APL. It's indecipherable gibberish to me every time I look at it, but I'm not even an APL amateur, much less professional, and that language seems built to be used by people that are very familiar with it. Is that wrong? No, they just aren't optimizing for learnability and community growth, as Python does, instead opting to make it as simple and useful as possible for experts to get what they need accomplished.
You can counter by saying that most code is read more than it's written, so readability is more important, and to that I would say that it depends on the type of code (scripting languages lend themselves to a lot of one-off scripts), and that readability is also a function of experience. If you want your code easily readable my amateurs, then keeping the capabilities you can use to those an amateur can understand is beneficial. If you want your code readable and understandable by experienced programmers, use constructs and control flows that they are experienced with, which is a much wider set of capabilities usually (if the language supports them).
I also wouldn't keep all the blocks on the same line, but it can be forgiven in a comment box.
I actually had that at first...
> I might even skip the `== 0` but just saying `(! $n % 15)`
...and that too. I changed them to be more likely to be obvious to even someone who has never seen Perl before. A lot of languages besides Perl have a "for" loop variant that is like a C "for" loop.
The formatting was indeed because it was in a comment box. I didn't want to take up too much vertical space on the page.
My scripts end up longer and more verbose typically (I might just not be great at Python) but also a lot more maintainable (I am not great at writing maintainable Perl and I use Python more often).
I also use Node.js for this a lot because of the ecosystem containing so many accessible scripts and dependency management while not great is heaps better than most other ecosystems.
Of course OpenBSD can't do that with Python rather then Perl (as explained in that email). They have a different set of constraints. I am only saying in practice I have found Python to be the better alternative for my personal stuff.