Hi Matthew,
On Thu, Jan 8, 2009 at 1:22 PM, Matthew Fuesz <[email protected]> wrote:
> But I find that the '!= 0' produces far more readable code, when the
> convention is consistently adhered to.
In *your* opinion. My opinion is less readable. For the projects you
are responsible feel welcome to make such a dictate.
> It is completely unambigous what is meant by a "if ( (a=b) != 0 )" statement;
> the intention was obviously to conditionally check the results of an
> assignment. Without the explicit conditional, it may become ambiguous as to
> whether the intention was to check on the assignment, or if it was a typo and
> supposed to be just a conditional.
By with more code come more pontenial for typo errors and algorithm
errors. The "completely unambiguous" mentality is broken, as simple
code that become more complicated doesn't not obviously become less
ambiguous, typically the more code you look at the less easy it is to
work out its meaning with close parsing of the text.
> And if you would find a statement "if ( (a==b) != 0 )", then you could catch
> the comparison instead of assignment; likewise, if ( a=b ) was found, it
> would indicate assignment instead of comparison. This holds, of course, only
> if consistency is mainted and the "standard" of using "!=" after the
> assignment is adhered to.
Following your logic we should also do:
if (bool_variable==true)
{
}
Rather than:
if (bool_variable)
{
}
As for consistently maintaining such a style, well it's off in lala
land. The OSG as over 350 contributors, it's hard enough keeping
tabbing and bracket indenting.
> As I said earlier, I prefer this way (explicit comparison) anyway - the fact
> that it saves me the warning is an added benefit beyond the readability issue.
>
> Of course, what is - IMO - the _absolutely_ most readable is to split the
> statement in two - i.e., "a = b; if ( a ) {}"
Again falling down the black and white programming hole, before it was
"completetly unabiguous" now its "_absolutely_ most readable", if this
was really true then would be no room for disagreement on logical
grounds. Both statements are false because they are personal opinion
not prove-able mathematical construct being dressed up as such.
To break your theory about readability go review the places where the
warning is produced and go refactor them and you'll find that they
often become less readable and maintainable. Yesterday I did review
lots of this code and considered exactly your suggested suggestion
myself and time and time again I found the using of assignment in the
comparison the neatest, most readable and maintainable solution. I
the one that has to responsibility for maintaining this code so it's
crucial to me that it has to be maintainable and bug free, if your
standpoint had legs then I would have already adopted it.
Programming isn't black and white, especially C++ programming.
Robert.
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org