Follow

Unix shell vs JavaScript 

Nobody would argue that Unix shell is a better programming language than JavaScript, right?

The shell is even slower than JavaScript, has way more arcane syntax, and as for typing — we laugh at JS for how their == works, but in shell, everything is a string, and sometimes also an array, but how exactly it's an array depends on IFS.

The only thing the shell is good at is gluing together other utilities.

Unix shell vs JavaScript 

Yet it's JavaScript that gets all the hate for how "weird" and badly designed it is. And the shell is generally regarded as something that cool hax0rs write in.

Have you seen people embarrassed they're writing shell scripts instead of doing "real programming"? I haven't.

Show thread

Unix shell vs JavaScript 

People keep misunderstanding what I am and am not saying, so, clarifications:

I'm not defending JavaScript (come on, you know me!)

This is not about GNU Bash or any specific shell implementation, this is about Unix shells in general

Show thread

Unix shell vs JavaScript 

Shell's intended for gluing other programs together, and is very good at it

But people want to program in shell, with functions, variables, loops, and so on — and the shell is bad at that, yet it seems nobody is concerned about that, at least nowhere as much as people like to shit on JavaScript for its quirks

Show thread

@bugaevc anyone who would argue that Unix shell is better OR worse than JavaScript is making a stupid argument

@sir if you're saying that they have a different purpose, you're right — but that doesn't change the fact that shell is being used as a scripting language oh so often, and it's terrible at it.

@bugaevc @sir I would say "shell is being used as an actual programming language so often and it's terrible at it" ;)

@bugaevc it's not bad at what it's designed to do: manipulate text, and pass text to and from different programs. Maybe with a little bit of logic mixed in.

@bugaevc really I don't know of anything better than shell scripts for that purpose

@sir that's my issue though: whenever I want to glue some programs together I reach for shell scripting; but then I discover I need sane types like lists and maps and sets and lists of lists, so I switch to Python, but then it's awkward to shell out to those other programs.

Why oh why isn't shell a better programming language :(

@bugaevc you could always mix in a little bit of awk. awk is underutilized imo

@bugaevc @sir Shell has vastly nicer syntax, is by all reasonable definitions a Lisp, is only slow if you're using a terrible, non-compliant shell, and doesn't actually have a difficult syntax to understand.

AT&T had their secretaries using it in the 1980s, and if secretaries can understand it, anyone should be able to. There are only like five things you actually need to learn to learn the underlying principles of it.

@kick @sir I guess beauty is in the eyes of... developer, but I find shell syntax pretty ugly (all those "esac"s and ";;"s and "$@"s).

And honestly, it's not like being a Lisp is a good thing (unless it's Emacs Lisp 😉).

I don't get what "compliance" has to do with performance, but what I meant is JavaScript is run by highly optimized JITs whereas the shell is all about spawning many processes and shoveling data around through pipes by copying it into kernel space and back.

@bugaevc @kick esac is clever and therefore good, hack the planet

@bugaevc @sir The entire existence of Javascript is based in one (mostly incompetent) dev trying to get Scheme (a Lisp) in his browser but messing it up and getting a monstrosity. Dissing Lisp in a discussion where you're defending Javascript is like dissing C in a discussion about C++: where do you think all of the tolerable parts were stolen from?

"esac" is from the Bourne Shell, which stole it from ALGOL-68, which is perhaps the most influential language in computer science, ever.

bash is a non-compliant POSIX shell. bash is slow because of the non-standard additions. Most people who insult the shell have only used a non-compliant shell.


You say "highly-optimized JITs," but I think about how the shell ran fast on PDP-11s yet V8 and IonMonkey (Firefox's JIT) both struggle on the low-end laptops of today.

@kick @sir
I'm not defending JavaScript, that's a ridiculous assumption. I'm saying that as a programming language, shell is even worse, but that fact goes curiously unnoticed by most, even those who vocally criticize and make fun of JavaScript.

I know about shell's relation to ALGOL; but that doesn't make the syntax any nicer.

@kick @sir Could you expand on your claims that GNU Bash is not POSIX compliant? I believe it tries to be, especially if you run it as /bin/sh. And why do you believe that it's specifically extensions over what POSIX requires that slow "non-compliant" shells down? In any case, I was specifically not referring to any particular shell, so pick whichever one you think is most compliant/performant.

@kick @sir Shell runs fast as long as you only use it to glue other fast programs together (which is after all its intended purpose). Imagine how "fast" those monstrous "web apps" would be if they were to write them in shell instead of JavaScript.

Unix shell vs JavaScript 

@bugaevc hmm.

i don't actually think i know anyone who thinks of shell as a _good programming language_ as such. a good tool along certain dimensions, sure, but not a good general purpose language.

shell definitely partakes of the turing tarpit thing[0], though. i think people aren't so much embarrassed or not about large shell scripts as they're either stuck with something that started small or unable to help themselves wrt the challenge.

[0]: en.wikipedia.org/wiki/Turing_t

Unix shell vs JavaScript 

@bugaevc

> Nobody would argue that Unix shell is a better programming language than JavaScript, right?

What? They're for different things. One is for system automation. The other is for showing drop-down menus on the websites.

Unix shell vs JavaScript 

@drq well, JavaScript is now being used for system automation too.

But what I mean is both are programming languages, both have variables, conditionals, loops, switches, functions and so on. And JavaScript is not doing great on that front, and gets mocked for that. Whereas the shell is doing much worse, yet everybody considers writing shell scripts to be OK and even cool.

re: Unix shell vs JavaScript 

@drq @bugaevc Uh, you do not need JS for drop-down menus for like… 4+ years. See https://hacktivis.me/ for an example.

Only use of javascript is for dynamic content where asking the server for each action is just a horrible thing to do. (And weird polyfills but please drop IE6)

Unix shell vs JavaScript 

@bugaevc @alexcleac kind of an interesting point.

Unix shell vs JavaScript 

@ndegruchy I would rather say that it is very nice point. It is more of a question of "first-class" citizen for achieving tasks. Bash is awful, but it is great for purpose it was created for. Same thing with JavaScript

@bugaevc

Unix shell vs JavaScript 

@bugaevc in this world where every developer is lamenting about something I was looking for a soulmate that thinks like me that is terrible to write programs in bash. I feel less lonely today.

Sign in to participate in the conversation
Mastodon for Tech Folks

This Mastodon instance is for people interested in technology. Discussions aren't limited to technology, because tech folks shouldn't be limited to technology either!