5 ms·
If one of my developers used "||" that way I would definitely throw some side eye
by joecarrot 2y ago
If one of my developers used "||" that way I would definitely throw some side eye
- JellyBeanThief 2y agoI was thinking exactly the same. You can write if (cond) { cons } on one line and get more readable code admittedly a few chars longer.
- alilleybrinker 2y agoCode patterns are social! What is strange to one is normal to another. The kind of pattern used here with the `||` might seem weird to some JavaScript developers, but it's pretty normal in shell scripts, and it's pretty normal in Ruby with `unless`!
- mmastrac 2y ago`||` is conventional in bash, but definitely not in JS. `x || value` is closer to conventional JS, but using it for control flow is certainly not common and a stylistic choice, for sure.
- deleted 2y ago[deleted]
- shiroiushi 2y ago>The kind of pattern used here with the `||` might seem weird to some JavaScript developers, but it's pretty normal in shell scripts Shell scripts are NOT known for being easy to read. They're full of obscure and sometimes frankly bizarre, arcane syntax that newcomers would have no idea about. Quick, what does "$#" mean? An experienced bash programmer would know, but no one else would. Shell scripts were never meant to be easy to read; they're just an extension of the shell syntax, and of course vary a lot from shell to shell (e.g. bash vs zsh vs ksh etc.).
- 65 2y agoDon't even need the curly braces. I do if (cond) doSomething(); all the time.
- MetaWhirledPeas 2y agoI must be their target audience because as soon as they used the example with || it all started making sense. This would have been fine too but it would trigger some people not to use {} if (!validateUserInput(user)) throwError(err.userValidationFailed); My preferred style might be closer to this. if (!userInputIsValid(user)) throwError(err.userValidationFailed);
- gnarlouse 2y agoIf one of my developers threw in a throw like that I would throw up in their mouth.