[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Booleans as integers
- Date: Mon, 27 Oct 97 22:44:40 -0800
- From: Andrew Begel <abegel@alum.mit.edu>
- Subject: Re: Booleans as integers
>Andy,
>
>> setpc-var not pc = yellow
>>
>> if your color is yellow, set pc-var to false (1), else set it to true
>> (0). (We do the opposite, because we want to count them up, and false is
>> 1, not 0.
>
>This kind of code is a very brief way of putting it. But doesn't it go
>against the reference manual's warning which discourages the use of
>boolean values as integers since they may be differently implemented in the
>future?
>A somewhat longer, but implementation-independent solution (and perhaps
>more readable) would be:
>
>ifelse pc = yellow [setpc-var 1] [setpc-var 0]
>
>Speaking about the issue of using boolean values as integers in general, I
>think it is also dangerous not only because the implementation of StarLogo
>may change. You may very easily make a mistake because the code is not
>readable. On the other hand, it is always easy to find a substitute like
>above.
>
Yep, you're right. I've been at Berkeley for the past few months and have
started programming in C. I've lost my good programming habits so
quickly... <shaking head>
As for making the compiler figure out when you're doing this, I think it
would take some effort. Right now, the compiler does enough checking to
make StarLogo work. Adding additional type-checking might be a good
project to work on. For me, I usually like fewer errors/warnings from the
compiler, since I'd rather see my code run and fail than not run at all.
Andy
(Another good project would be to "fix" the true and false values to C
conventions, instead of Pascal conventions. Then most intuitions about
true and false would be correct.)
Andrew Begel
Dept. of Computer Science
UC Berkeley