Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.



  condition && 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.)


I prefer || and && because I can never seem to remember the bash `if` syntax.


Sure, 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.


I 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...




Consider applying for YC's Winter 2027 batch! Applications are open till November 2.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: