The boolean tag has no wiki summary.
4
votes
4answers
221 views
Naming boolean variables: negated or not
A few years ago, I was in a software engineering class and the teacher explained how messages, options, variables, etc. should not be negated to avoid confusion. He gave the example (something like):
...
2
votes
3answers
422 views
Computers that operate exclusively on boolean algebra
I was wondering if there are any computers that operate exclusively on boolean operations. For example, no add, sub, mult, or div in the instruction set (although these could be emulated with the ...
0
votes
1answer
121 views
design patterns in Javascript - toggle functionality [duplicate]
My goal is to add some functionality to the bxslider script - in this case, I want to be able to enable/disable a keyboard event handler AFTER a slider is instantiated.
I guess this code is self ...
25
votes
3answers
1k views
Why does the boolean type in C++ support `++` but not `--`?
Why does the operator -- not exist for bool whereas it does for operator ++?
I tried in C++, and I do not know if my question apply to another language. I will glad to know also.
I know, I can use ...
-1
votes
3answers
172 views
Should I always use “is” as prefix for boolean variables? [closed]
Should I always use is as prefix for boolean variables? What about booleans that indicate something in past? Should I write isInitialized or wasInitialized? Should I write for properties IsManyMembers ...
4
votes
1answer
221 views
Should methods that return boolean be named after a question or an assertion? [closed]
Many naming conventions recommend that methods returning a boolean (also called predicate methods) should be named after a question. My question is: don't they really mean the methods should be named ...
2
votes
3answers
636 views
8 bit and 1 byte, is this a valid question to be asked?
I saw these question in our school's past paper, and I'm wondering if this is a valid question.
How big is bool in C and C++?
A) 1 bit
B) 4 bit
C) 8 bit
D) 1 byte
What is ...
0
votes
1answer
296 views
Is there any reason zero should still equal false in a new programming language? [duplicate]
I understand that 0 is false because math established that a long time ago and C established it in the programming world, as talked about here. However, other than following established conventions, ...
-2
votes
4answers
286 views
What are the advantages of converting empty strings to evaluate to true as compared to false? [closed]
When converting a string to a boolean, what are the advantages of having a programming language evaluate an empty string as true and what are the advantages of having it evaluate it to false?
0
votes
0answers
47 views
Boolean condition before variable [duplicate]
I have noticed this style from time to time:
if ( 0 == myVar )
Rather than:
if ( myVar == 0 )
Is this just the individual programmers idiom? A defensive programming style? Does anyone know if it ...
28
votes
4answers
11k views
When should you use bools in C++?
We had an assignment for our class where we had to create a Tic-tac-toe game. People like to complicate themselves, so they wrote complex games which included menus. At the end of the game, you had to ...
16
votes
12answers
2k views
Correct comment to put for boolean function arguments that are “false”?
From some open source projects, I gathered the following coding style
void someFunction(bool forget);
void ourFunction() {
someFunction(false /* forget */);
}
I always have doubt about what ...
0
votes
1answer
149 views
Truth condition testing with BOOL
BOOL myBool;
myBool = YES;
...
if (myBool) {
doFoo();
}
I have read that because there are instances where the above does not actually call the doFoo() function, it is best to instead always test ...
3
votes
6answers
408 views
Are there any valid use-cases for eager boolean evaluation?
Today I learned about eager boolean evaluation. In the following example, Bar() will be evaluated even when Foo() is true.
if (Foo() | Bar())
This answer on SO has an example:
if ((first = (i == ...
3
votes
1answer
82 views
Tests for emptiness vs tests for nothingness
Is there any consensus between languages how tests for emptiness are distinct from tests for noneness? In python the following expression is false:
{} is {}
However this expression evaluates to True
...
2
votes
5answers
461 views
The rationale behind Falsy values [closed]
I'm wondering what the arguments for/against Falsy values are. On what principles would you decide to add or exclude them from a language? Are there any problems you could see them causing off-hand?
...
5
votes
4answers
648 views
Returning a boolean when success or failure is the sole concern
I often find myself returning a boolean from a method, that's used in multiple locations, in order to contain all the logic around that method in a single place. All the (internal) calling method ...
4
votes
1answer
325 views
boolean or Boolean?
I was doing edit reviews on Stack Overflow and found out that people keeps correcting the word "boolean", replacing it with "Boolean" when it appears in text (but not in source code, of course). And ...
20
votes
2answers
3k views
Why is Java boolean primitive type name not 'bool'?
Java has
int and Integer
boolean and Boolean
This seems a bit inconsistent, why not either
bool vs Boolean to use an established shorter name for primitive type?
or
integer vs Integer to ...
29
votes
2answers
2k views
Why is a Boolean value stored as a byte inside of a computer when it only requires one bit
I recently started learning to write code, and in my book I came across this question. "Why is a Boolean value stored as a byte inside of a computer when it only requires one bit?" can someone shed ...
39
votes
17answers
4k views
Why Use !boolean_variable Over boolean_variable == false
A comment on this question: Calling A Method that returns a boolean value inside a conditional statement says that you should use !boolean instead of boolean == false when testing conditions. Why? To ...
6
votes
5answers
2k views
Why is there both a short-circuit OR as well as unshort-circuited variation of that operator in C#?
Periodically, I wonder about this:
The short-circuit OR would always return the same value that the unshort-circuited OR operator would?
I expect that the short-circuit OR would always evaluate ...