[Gambas-user] static const?
Doriano Blengino
doriano.blengino at ...1909...
Fri Apr 16 10:11:46 CEST 2010
Charlie Reinl ha scritto:
> Am Donnerstag, den 15.04.2010, 21:07 +0300 schrieb Jussi Lahtinen:
>
>> Yes, you can test it.
>>
>> This should generate error:
>> If 1 = 2 And 1 / 0 Then Print "test"
>>
>> This should not.:
>> If 1 = 2 And If 1 / 0 Then Print "test"
>>
>>
>>>>
>>>> if i<tabstrip1.count and tabstrip1[i].caption=""
>>>>
>>>> can fail, if I understand well. Perhaps I must check a few lines of code...
>>>>
>>>>
> yes you are right for that example
>
> (my teacher said never try to divide something by 0).
>
> And I do not understand why/what/where.... that condition is/could be
> good for ... 1/0 !?
>
> but
> If 1 = 1 And 1<> 2 Then Print "test"
> and
> If 1 = 1 And If 1<> 2 Then Print "test"
>
> works the same way.
>
The problem is this. Suppose you have to test a property of a object; if
the object exists, and its property value is "1" you do something:
if theobject<>NULL and theobject.number=1 THEN ...
The above statement is wrong, because gambas evaluates the second
expression even if the first is false; doing so, it tries to read a
property of a non-existent object. I checked the documentation (perhaps
a little old), and this behavior is not specified. It is true that you
find an alternative syntax, looking strange at first but nice, like "IF
expr and IF otherexpr THEN ...", but this does say nothing about the
classic syntax.
Coming from years of programming in C and pascal, I gave for normal that
short-circuit is common practice, but this is not the case. So I must
check a few lines of code.
Better explanation can be found on wikipedia:
http://en.wikipedia.org/wiki/Short-circuit_evaluation
Ciao,
Doriano
More information about the User
mailing list