Is there a technic to avoid this bug

Diez B. Roggisch deets at nospam.web.de
Tue Feb 27 07:49:42 EST 2007


hg wrote:

> Hi,
> 
> In C/C++ I got used to  write an expression like so:
> 
> #define TEST 0
> 
> if (TEST == value)
> {
> 
> }
> 
> in order to avoid the usual bug:
> if (value = TEST)
> {
> 
> }
> 
> In a relatively similar domain, I spent a few hours find this bug:
> 
> value == self.Get_Value()
> if value == WHATEVER:
>    do this
> 
> instead of
> value = self.Get_Value()
> if value == WHATEVER:
>    do this
> 
> Is there a way to avoid such a bug with some type of construct ?

No. In a language inherent with sideeffects, there is nothing that should
force you to not write that.

However, it might be that either pychecker or pylint will give you a warning
for such statements.

Diez



More information about the Python-list mailing list