Re: Position of test values in conditional expressions
From: Walter Tross (walter_at_waltertross.com)
Date: 06/20/04
- Next message: valentin tihomirov: "Re: Java's performance far better that optimized C++"
- Previous message: Ioannis Vranos: "Re: Java's performance far better that optimized C++"
- In reply to: Ney André de Mello Zunino: "Position of test values in conditional expressions"
- Next in thread: Ben Measures: "Re: Position of test values in conditional expressions"
- Reply: Ben Measures: "Re: Position of test values in conditional expressions"
- Reply: William: "Re: Position of test values in conditional expressions"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 20 Jun 2004 16:04:22 +0200
Ney André de Mello Zunino 2004-06-20 :
> I have noticed, in a lot of C and C++ code, that many programmers seem
> to prefer putting the test values first in conditional expressions.
> I.e., they would rather write this:
>
> if (-1 == foobar())
>
> than this:
>
> if (foobar() == -1)
>
> The second form looks more natural and easier to read IMHO and is the
> one I have always used. However, given the high ocurrence of the first
> one, I would like to know the implications of using one way or the other.
As others have already explained, it helps in avoiding the error of
writing an assignment where an equality comparison was intended.
I personally dislike this trick, because it only helps in *initially*
avoiding a mistake, while the more difficult to read code *remains*.
If you rely on this kind of trick to write correct code, it means that you
are not doing any testing, which is the worst mistake you can make.
Walter Tross
- Next message: valentin tihomirov: "Re: Java's performance far better that optimized C++"
- Previous message: Ioannis Vranos: "Re: Java's performance far better that optimized C++"
- In reply to: Ney André de Mello Zunino: "Position of test values in conditional expressions"
- Next in thread: Ben Measures: "Re: Position of test values in conditional expressions"
- Reply: Ben Measures: "Re: Position of test values in conditional expressions"
- Reply: William: "Re: Position of test values in conditional expressions"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|