I’ve been programming in C-derived languages for a couple of decades now. Somewhere along the line, I decided that I no longer wanted to write:
if (var) // in C if ($var) # in Perl
when what I meant was:
if (var != 0) if (defined $var and $var ne '')
I think part of it is that I have a strongly-typed brain and in my mind, ‘if’ requires a boolean expression.
Or maybe it’s because I use Perl so much and truth and falsehood in Perl is such a mine-field.
Or maybe it’s just because these days, I’m mainly a Java programmer.
What are your preferences and why?
I like my
ifs to make sense when read aloud: