Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
Nope, I'd put both statements in variables with names describing what the value means...
Edit: ... Or skip the first linebreak:
if(prettyLong(thing) ||
thisOther[thing]) {
//...
}
Or however you'd like your curlies aligned. -
Never seen that before.
I always write longer if statements like this:
if(longCondition ||
otherCondition) {
} -
Root797676yI'd attach the parentheses and vertically align the conditions, but yes. It's significantly easier to read two similar lines than one very long line.
Or if it's more complex, I'd break up the logic into a builder-like approach:
condition = blah
condition = condition && blah
condition = condition || blah
...
if (condition) { ... } -
Doesn’t matter what language, just pure logic, these are always true:
Not a or not b = not (a and b)
Not a and not b = not (a or b) -
Only thing I do for readability is place the comparison operator on the next line. Like this:
if (
doSomeCoolStuff(user)
|| doSomeBoringStuff(user)
) {
//
} -
I'd write an (and) statement instead of (not or not) and put it all on one or two lines max
-
@frickerg I guess it depends on the situation. In some cases an "or" statement can have quite the performance impact, since the second statement isn't executed if the first statement is true
-
xewl41266yYeah, do that stuff daily, though I newline before the operators, not after. I know its culprits, eg. assigning a variable can only be done in the very last statement etc.
I'm fine with it as long as I can interpret what's going on.. and this isn't even close to what I sometimes have to do to implement certain logic altogether. -
Fexell6566yHmm. I have never written if statements this way before. I understand the argument for readability, but it feels like a pattern-breaker, unless you write every if statement like that. If I would come across that it would take me a second to realize that that is an if statement.
-
@dennie170 it's been a while since my algorithmics course, but isn't it the same for AND too? Despite the efficiency, I don't want to use chained NOT expressions in one statement for better readability.
-
xewl41266yAlso, that console log.. "propertydoesnt exist" at least chain the property variable to it.. so that the debug makes sense..
console.log('property doe...', collection, property);
Related Rants
The way this if statement is written (across multiple lines) is really weird to me. Anyone here that writes if statements like this?
random
if statement