Hi,

Sukender wrote:
Hi Matthew and JP,

Well it's always a bad idea to write *many* things in a single line in C/C++. I already saw things 
like "tab[++x] = (y=z++)", which could be dangerous. I even saw a "x = x++", 
which is an undefined behaviour (does not do the same depending on the type of x, and depending on 
the compiler).
Well, of course, it has nothing to see with the simple "if (a=b)" in our 
current discussion though.

I got an idea: we should extensively use the "," operator and code with no 
whitespaces and no carriage returns... :P

Yes, this way it is easy to point a debugger to the appropriate line of code :)

jp

Don't you know the IOCCC (International Obfuscated C Code Contest)? That's 
quite fun: http://www.ioccc.org/

Sukender
PVLE - Lightweight cross-platform game engine - http://pvle.sourceforge.net/


Le Thu, 08 Jan 2009 14:36:59 +0100, J.P. Delport <jpdelp...@csir.co.za> a écrit:

Hi,

Matthew Fuesz wrote:
Robert Osfield wrote:
Hi Sukender,
Code readability is key to spotting algorithm
errors, so any slip in readability is something to take very seriously
which is why the  !=0 is not what I would deem a good programming
practice.


But I find that the '!= 0' produces far more readable code, when the convention 
is consistently adhered to.

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.

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.

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 ) {}"

Well stated, I agree with everything you've said and second the split
statement approach.

jp


------------------------
Matthew W Fuesz
Software Engineer Asc
Lockheed Martin STS

------------------
Read this topic online here:
http://osgforum.tevs.eu/viewtopic.php?p=4303#4303





_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


--
This message is subject to the CSIR's copyright terms and conditions, e-mail legal notice, and implemented Open Document Format (ODF) standard. The full disclaimer details can be found at http://www.csir.co.za/disclaimer.html.

This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. MailScanner thanks Transtec Computers for their support.

_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to