[Gambas-user] INC and DEC on BOOLEAN data...

Benoit Minisini gambas at ...1...
Sun May 11 01:15:49 CEST 2008


On dimanche 11 mai 2008, you wrote:
>    IMHO this is broken thinking. It might be a little more typing to use
> VarName = NOT VarName but it is decidedly more transparent as to what
> datatype 'VarName' is and what is being done to it.
>
> Success = Not Success
>
> vs
>
> INC(Success)
>
> DEC(Success)
>
>    In the first example it is very clear what is being done, even when
> Hungarian notation is not being used, whereas in the second example all
> that is clear is that a value is being incremented or decremented. INC
> and DEC implies a change in direction (up or down) to a numeric value,
> while NOT implies a change in state, which is more analogous to a toggle.
>
>    I think, and perhaps I'm wrong on this, that a 'data type mismatch'
> error is the proper response to those trying to INC or DEC a boolean.
>   Sorry, I just had to reply, when I see things like this it makes me
> cringe, like someone dragging their fingernails on a blackboard makes me
> cringe.
>
>
> Kindest regards
> Stephen Bungay
>

Boolean and Integer values can be converted into each other in Gambas:

True -> -1
False -> 0

0 -> False
Any other value -> True

Incrementing or decrementing a boolean variable actually incremented or 
decremented its integer converted value.

INC False -> Inc 0 -> 1 -> True
INC True -> Inc -1 -> 0 -> False

DEC False -> Dec 0 -> -1 -> True
DEC True -> Dec -1 -> -2 -> True ? 

Weird, so this was fixed in Gambas 2.6, so that DEC True -> False. Otherwise, 
you will have to remember that INC toggle, but not DEC. I found that too 
complex for my own brain.

This is coherent with the common behaviour of Gambas. I mean you can INC or 
DEC dates too, as Date and Float can be converted to each other.

You can ignore this feature if you don't like it. Anyway, it cannot be removed 
in 2.x for backward compatibility reasons.

I could remove it in 3.0, and replace it by a NOT instruction that would do 
the same thing only for booleans:

NOT MyMenu.Checked ' for example

Regards,

-- 
Benoit Minisini




More information about the User mailing list