python for this C: "if ((a = b(c)) != NULL)"

Eric Brunel eric.brunel at pragmadev.com
Tue May 14 10:40:17 EDT 2002


David Carson wrote:
>> a = b(c)
>> if a:
>>   ...
[snip]
> 
> OK, so I wasn't quite clear in my original post.  I got four fine
> answers like this one -- that is how I do it too.
> 
> They lack the other criterion that makes me use this style in C in the
> first place -- brevity.  I choose the C syntax in the header because I
> can save a line and it is as clear and readable as the alternative
> of doing it on two lines (as all these solutions suggest).

For an experienced C programmer, maybe; not for anyone. I had to read the 
statement 3 or 4 times to understand what it does. For me, "a = b(c)" is a 
statement and has no reason to have a value. The real test definetely is 
"if ( a != NULL )". Writing it on one line is for me totally unclear and 
very hard to read. I'd never do that, even in a C program...

Just MHO, of course...

- Eric Brunel <eric.brunel at pragmadev.com> -
PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com




More information about the Python-list mailing list