I've been a professional C, Perl, PHP and Python developer.
I'm an ex-sysadmin from the late 20th century.
These days I do more Javascript and CSS and whatnot, and promote UX and accessibility.
Given that your "ouchy" if/elses are only checking for truthiness, you'd miss out the a = a; part in the real world, though.
// ✅ If/Else is much betterif(a){a=a;// do something else}else{a=b;}
becomes just this:
if(!a){a=b;}
and copes with specific tests like:
if(a===undefined){a=b;}
and that doesn't seem long or awkward to me; it seems explicit and readable.
Personally, I like the Elvis style (though it looks more like Jonny Bravo to me...) or the null coalescing operator you have in other languages (like SQL and nowadays even PHP), which has the benefit of being chainable like the || method.
Given that your "ouchy"
if
/else
s are only checking for truthiness, you'd miss out thea = a;
part in the real world, though.becomes just this:
and copes with specific tests like:
and that doesn't seem long or awkward to me; it seems explicit and readable.
Personally, I like the Elvis style (though it looks more like Jonny Bravo to me...) or the null coalescing operator you have in other languages (like SQL and nowadays even PHP), which has the benefit of being chainable like the
||
method.The code in this segment is backwards - you're setting
a
toa
only if it isundefined
, and using b in all other cases.