Distinctive features of performance, I believe that logical and integer numbers are two fundamentally different concepts in programming. Boolean represents a condition; an integer represents a number. Errors are easily injected if you do not strictly keep the value of your integer-boolean 0 or not 0, and why bother even when you can just use boolean values that allow you to perform security / type checking? I mean, take a method:
doSomething(int param)
Only one method / not / implies that the parameter is interpreted as boolean. Nobody will stop me from going through the year 1337, and no one will tell me what will happen if I do this - and even if he clearly documented so as not to pass the value 1337 to the method (but only 0 or 1), I can still This . If you can prevent errors during compilation, you should.
doSomething (bool param)
allows only two values: true and false, as well as incorrect.
Also, your examples of why integers would be better than booleans are incorrect.
if x is True: x = False else: x = True
can be written as
x != x
while your whole alternative is:
x = abs(x-1)
would require me to know:
- What possible values of x can have
- what the abs () function does
- why 1 is subtracted from x
- what it really is / does /. What is he doing?
The second example is big wtf for me.
if x is False: a = 0 else: a = 5
can be written as:
a = (x)? fifty;
while your whole alternative
a = 5*x
again requires me to know:
- What is X?
- What could be X?
- What happens if x = 10? -one? 2147483647?
Too many conventions. Use booleans for readability as well as common sense and error free predictable code.
fwielstra
source share