in reply to Re: Avoiding silly programming mistakes
in thread Avoiding silly programming mistakes
{if (0 == $foo) vs if ($foo == 0)} The reason some people recommend the latter is because if you accidently type the == equality operator as the = assignment operator, you will get an error (not so for the former). Since I vary rarely get bitten by this, I still use the former.
That's a C thing; that is, a practise that was used among C programmers long before Perl programmers started coding.
It's not really necessary to do so in Perl; with warnings on, if you mistake the operator, Perl will warn (Found = in conditional, should be == at ...). I think some C compilers (like gcc) will warn if you have an assignment in a conditional as well; which can be disabled by using an additional set of parenthesis.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: Avoiding silly programming mistakes
by Limbic~Region (Chancellor) on Aug 20, 2008 at 13:56 UTC | |
by moritz (Cardinal) on Aug 20, 2008 at 14:04 UTC | |
by JavaFan (Canon) on Aug 20, 2008 at 14:11 UTC | |
by Limbic~Region (Chancellor) on Aug 20, 2008 at 14:48 UTC | |
Re^3: Avoiding silly programming mistakes
by Jenda (Abbot) on Aug 29, 2008 at 16:33 UTC | |
Re^3: Avoiding silly programming mistakes
by kyle (Abbot) on Aug 29, 2008 at 17:56 UTC |
In Section
Seekers of Perl Wisdom