I have another method for the isEmpty case, but often I find it more readable to have if statement logic checks for a positive condition rather than a negative one. I read somewhere, I think it was Clean Code, that using positive logic requires less cognitive load when reading through the code. Especially when you are checking for more than one condition.
Just like you said: positive logic requires less cognitive load
For that reason, checking for a negative logic first and quit if true should be safer, more concise and readable than nesting two different logic inside an if/else statement
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I have another method for the isEmpty case, but often I find it more readable to have if statement logic checks for a positive condition rather than a negative one. I read somewhere, I think it was Clean Code, that using positive logic requires less cognitive load when reading through the code. Especially when you are checking for more than one condition.
Which is more readable?
or
I prefer the second.
Note: isEmpty is an rxjs operator since that could be confusing I will call it something else like safeIsEmpty.
Just like you said: positive logic requires less cognitive load
For that reason, checking for a negative logic first and quit if
true
should be safer, more concise and readable than nesting two different logic inside anif/else
statement