[Paraview-developers] Problem in the ParaView code

David Cole david.cole at kitware.com
Mon Sep 12 12:13:50 EDT 2005


Writing "good" code in a group setting is all about how understandable 
the code is to a wide variety of programmers...

Each line of code should be clear, accurate and precise. There's 
absolutely no need to keep the line count or size of source code files 
down to a bare minimum anymore. Trying to achieve your goal in a "single 
line of code" is just plain silly. Especially when two or three simple 
lines are much clearer than the single line with lots of parens or 
complex implied ordering.

Clarity and simplicity make for good long term maintainability. Which 
should be a primary goal of any open source project with many diverse 
contributors.

Thanks, Ken for the countergrumble. I wholeheartedly agree.


David

Moreland, Kenneth wrote:

> <countergrumble>
>  
> gcc is doing exactly as it should.  It knows very well the order in 
> which the operations should occur.  If it didn't, it would have given 
> an error.  A warning is specifically for something that is technically 
> correct but can easily lead to a problem if the programmers are not 
> very careful.
>  
> In this case, although the meaning is clear to the compiler, it is not 
> at all clear to a human without careful consideration.  Case in point: 
> Andy didn't fix this himself because he was not positive on the order 
> of operations.  Had Andy (or anyone else, not to pick on Andy) been 
> editing this code for other reasons and was not alerted by the 
> warning, he could easily have misinterpreted the line of code.
>  
> This warning is similar to the one given when you use an assignment 
> instead of comparison inside a conditional:
>  
>     if (foo = bar())
>  
> Although the expression is unambiguous (call function bar, put it's 
> result in foo, then check if foo is non-zero), it's considered 
> dangerous due to the visual similarity of operators = and ==.  This 
> particular warning has saved me many, many hours of debugging.  And 
> that's what warnings are all about.
>  
> </countergrumble>
>  
> -Ken
>
>     ------------------------------------------------------------------------
>     *From:* paraview-developers-bounces+kmorel=sandia.gov at paraview.org
>     [mailto:paraview-developers-bounces+kmorel=sandia.gov at paraview.org]
>     *On Behalf Of *Thompson, David C
>     *Sent:* Saturday, September 10, 2005 2:09 PM
>     *To:* Andy Cedilnik; ParaViewDev
>     *Subject:* RE: [Paraview-developers] Problem in the ParaView code
>
>     <grumble>It's a perfectly valid expression; since the assignment
>     is parenthesized, it must occur before the multiplication. And
>     the value of any assignment statement is the value assigned.
>     So gcc should know better than to emit a warning!</grumble>
>
>------------------------------------------------------------------------
>
>_______________________________________________
>Paraview-developers mailing list
>Paraview-developers at paraview.org
>http://public.kitware.com/mailman/listinfo/paraview-developers
>  
>



More information about the Paraview-developers mailing list