4 ms·
> it's hard to understand how 2k LoC are probably 50 LoC done wrong I challenge you to reimplement the shell script that grandparent linked in 50 LOC. In fact,
by majewsky 9y ago
> it's hard to understand how 2k LoC are probably 50 LoC done wrong
I challenge you to reimplement the shell script that grandparent linked in 50 LOC. In fact, shell script has the chance to be a lot more succinct than other languages for a lot of administrative tasks since the invocation of other programs is a first-class citizen. For example, compare this Go snippet:
cmd := exec.Command("apt", append([]string{"install"}, dependencies...))
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err := cmd.Run()
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
os.Exit(1)
}
to its equivalent in shell script:
if ! apt install ${DEPENDENCIES[@]}; then
echo "exit status: $!" >&2
exit 1
fi
Or even just "apt install ${DEPENDENCIES[@]}" with "set -e".
Finally, what is it with sysadmins maintaining large scripts while at the same time quipping that they are not programmers? A script is very much a program, and a scripting language is very much a programming language.
- arca_vorago 9y ago> Finally, what is it with sysadmins maintaining large scripts while at the same time quipping that they are not programmers? A script is very much a program, and a scripting language is very much a programming language. You are correct, but I mostly use this preface to let people know I don't have the detailed formal training in programming most devs do. So while I can wiggle my way around perl/python/bash/awk/sed and other "systems languages" just fine I am constantly finding out how much I don't know. I suppose in the early hacker days sense of the word most of us are programmers.
- majewsky 9y ago> I am constantly finding out how much I don't know. You think that once you have a CS degree, it's not like that anymore? If anything, that feeling gets more and more common over the years.
- agumonkey 9y agoIt would be a fun challenge, note that for instance the first part of the script is dependency check, the whole is basically `import a,b,c,d` in meaning. It's true that calling programs shortens tremendously, but every time you have to glue things together you're back to grep/sed and all the fragile bash idioms. Of course you could have standalone programs to do that, in the end it would be as having a non bash programming language in disguise
- geocar 9y ago> what is it with sysadmins maintaining large scripts while at the same time quipping that they are not programmers? We've met some programmers, and don't want to be compared to that[1]. Seriously. Programmers will embark on some massive mission that Apache and dumb CGIs can do[2] Programmers will justify their slow software by saying it's readable, or by saying that the JIRA ticket didn't specify how fast the solution needed to be. Programmers will make user interfaces that require clicking multiple times to find some bug, then require the report tediously repeat those clicks, complain that the bug report wasn't accurate (can't find a button that says "OK" when it says "Close", and there's no other buttons). Programmers will actually shit in the pool, and say it improves readability. Seriously: I have seen programmers delete perfectly working code and replace it with something broken (especially on the edge cases) and then ask the sysadmin team to wake up at 3am to restart their software every night. Code that was working fine for years. Code that wasn't even in their project. Fuck that. [1]: https://news.ycombinator.com/item?id=16155641 https://news.ycombinator.com/item?id=16155641 [2]: http://marcio.io/2015/07/handling-1-million-requests-per-minute-with-golang/ http://marcio.io/2015/07/handling-1-million-requests-per-min...
- majewsky 9y agoWhat you mean is not "programmer", but "software engineer". Everyone who introduces themselves as a "software engineer" to me starts with -100 points on the scorecard in my mind, because that's exactly the sort of people you're talking about.
- lmm 9y ago> In fact, shell script has the chance to be a lot more succinct than other languages for a lot of administrative tasks since the invocation of other programs is a first-class citizen. Sure, so the fair comparison to make is with calling library functions - all those other programs had to be implemented separately too. If I were reimplementing the linked script I'd use something like Puppet where "ensure package installed" is a first-class citizen too.