Examples of where I've started migrating to short-circuit evaluation:
PHP
$id=0;//initialized in case of no result
$r=mysql_query(SQL);
if($r && mysql_num_rows($r)>0){
list($id)=mysql_fetch_row($r);
}
becomes
$id=0;
$r=mysql_query(SQL);
$r && mysql_num_rows($r)>0 && list($id)=mysql_fetch_row($r);
JavaScript
var Req=jQuery.ajax(OBJECT);
//Something has happened and now i want to abort if possible
if(Req && Req.abort){
Req.abort();
}
becomes
var Req=jQuery.ajax(OBJECT);
//Something has happened and now i want to abort if possible
Req && Req.abort && Req.abort();
I'm familiar with the short if
style of
if(Req && Req.abort) Req.abort();
but it feels clunkier than short-circuit evaluation.
&&
, this is a generic best-practices question, and therefore off-topic. \$\endgroup\$