Hacker News new | ask | show | jobs
by binary132 698 days ago
Shell is just one way. There’s nothing that says we can’t do better than shell, but what it’s good at is saving programmer time when the need isn’t there for more, and Rust is definitely not good at that.
1 comments

My rule of thumb:

    Shell: <= 5 lines
    Python: <= 500 lines
    Rust: > 500 lines
Although to be honest I'd be perfectly happy if Shell was restricted to single line commands only.

I've wasted a lot of time and energy deciphering undebuggable shell scripts that were written to "save programmer time". Not a fan.

My rule (and the code review policy I impose) emphasizes complexity instead - a 50 line shell script is great if it doesn't use if or case. (It's not so much of a strict rule as "once you're nesting conditionals, or using any shell construct that really needs a comment to explain the shell and not your code, you should probably already have switched to python." This is in parallel with "error handling in this case is critical, do you really think your bash is accurate enough?")

I wasn't the strictest reviewer (most feared, sure, but not strictest) at least partly because my personal line for "oh that bit of shell is obvious" is way too high.

Nothing is as obvious as it could be when it’s 3am and you’re debugging a production outage. :)
This rule of thumb is clearly too simplified, even as far as the definition goes.

Sometimes you just want to execute 50 lines with little logic.

Sometimes you just have some simple logic that needs to be repeated.

Sometimes that logic is complicated, sometimes it is not.

Sometimes someone writes 50 lines of simple logic. And then sometimes someone else needs to figure out why it’s not working. That person gets very cranky and wastes a lot of time when those “simple” 50 lines aren’t debuggable.

If shell scripting didn’t exist I would be totally fine with that. There are far more scripts that I wish were written in a real language than the other way around.