The tag has no wiki summary.

learn more… | top users | synonyms

1
vote
3answers
135 views

negative boolean expressions and eager boolean OR

I come across these kinds of expressions and I have hard time reading it. How do you read it properly to see if it is the right logic when debugging. if (!(userLoggedIn || isAdmin)) { ...
0
votes
2answers
150 views

boolean operations in C using bitfields

I am trying to implement boolean data type in C. Basically, I am working with sets. The following code can be used to access each bit but I am unsure whether I can represent sets using this method. ...
1
vote
1answer
168 views

What is this boolean law?

A friend of mine has shown sometime ago the name of the below boolean technique/law but I forget that name unfortunately. Does someone know what it's called? example in C language: !(a || b) It's ...
3
votes
1answer
177 views

How to create an algorithm for determining Boolean Tautologies

So i am right now exploring some topics in a proof course and it occurred to me to try to create a boolean tautology solver. I would like an algorithm that is more efficient than brute force. Problem ...
4
votes
4answers
308 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): ...
-1
votes
1answer
168 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 ...
-1
votes
3answers
374 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 ...
27
votes
3answers
2k 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 ...
5
votes
1answer
251 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
4answers
299 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
1answer
327 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, ...
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 ...
17
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 ...
3
votes
6answers
420 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
3answers
698 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
151 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
1answer
87 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
530 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
941 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
374 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 ...
28
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 ...
29
votes
4answers
15k 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 ...
2
votes
3answers
473 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 ...
41
votes
17answers
5k 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 ...
18
votes
6answers
2k views

How to turn truth table into smallest possible if / else block

How can I take a truth table and turn it into a compacted if block? For instance, let's say I have this truth table where A and B are conditions and x, y and z are possible actions: A B | x y z ...