3 ms·
I agree. I also find unless statements to be difficult to read. I use this pattern all of the time in my JavaScript: if(!foo) { maybeDoSomething();
by MatthewPhillips 15y ago
I agree. I also find unless statements to be difficult to read. I use this pattern all of the time in my JavaScript:
if(!foo) {
maybeDoSomething();
return;
}
bar();
This lets me early exit, if needed, while letting the meat of the function not suffer from unnecessary indentation.
The unless statement makes the early exit seem like the default action rather than the exceptional action it (hopefully) is.