4 ms·
Strongly disagree on elegance of [[ condition ]] || cmd and [[ condition ]] && cmd. Every developer has read enough if statements to understand if then else at
by the_jeremy 6y ago
Strongly disagree on elegance of [[ condition ]] || cmd and [[ condition ]] && cmd.
Every developer has read enough if statements to understand if then else at a glance. Few people write enough bash scripts to have that same instant parsing of [[ condition ]] && cmd or [[ condition ]] || cmd, especially when intermingled.
I like the idea of cmd || { raise error; } that others have mentioned, but I hate the idea of using these in place of an if statement to save 2 lines.
- dragonwriter 6y agocondition && action condition || action (or the equivalent for languages where the logical operators are written differently) are not bash-exclusive idioms; I've seen them in a number of expression-oriented languages (less frequently on statement-oriented languages where the particular action is a function rather than a statement, but the fact that it isn't usable consistently in those. languages tends to make it less idiomatic there.)
- mmastrac 6y agoI prefer || and && because I can never seem to remember the bash `if` syntax.
- the_jeremy 6y agoSure, it's weird to write (`then` is a separate statement, it has to end with `fi`, that's different), but I prefer making things easier to read than write. I believe that it's easier to read that boilerplate even if you have to look up how to write it.
- mmastrac 6y agoI guess I've been reading that construction long enough that it's obvious (at least to me). It's also helpful that the same construction is common in obfuscated and tightly-compiled Javascript...
- deleted 6y ago[deleted]