Skip to main content

Questions tagged [boolean]

Filter by
Sorted by
Tagged with
7 votes
8 answers
945 views

According to Is it wrong to use a boolean parameter to determine behavior?, I know using boolean parameters to decide the behaviour is bad, for example, when using boolean parameters as the following: ...
wcminipgasker2023's user avatar
0 votes
3 answers
252 views

I know there are some questions about boolean flags: Is it wrong to use a boolean parameter to determine behavior?, Multiple boolean arguments - why is it bad? which indicates the following code is ...
wcminipgasker2023's user avatar
3 votes
2 answers
6k views

I like the practice of naming boolean variables with a prefix like "is", "has", "should", or "can". But what about the functions that produce those results? ...
Ryan's user avatar
  • 167
0 votes
2 answers
548 views

.NET Boolean type usually makes if else pair all over the code. Functional Boolean should be more like Either type. Ideally represented as Either<Unit, Unit>. However, my issues with Either type ...
TIKSN's user avatar
  • 109
4 votes
5 answers
421 views

I have a disagreement with one of my colleagues on whether or not functions should have inverse functions available. I would like to know when/if inverse functions should be used. For example, say we ...
Byebye's user avatar
  • 346
3 votes
5 answers
1k views

I commonly use a boolean condition/variable when it's something too big or complicated and takes too much space by itself inside ifs - basically to avoid repeatability and thus improve readability. E....
PascCase's user avatar
1 vote
6 answers
4k views

I have had hard times naming boolean fields. On the one hand, i've read that it is good to name them as affirmative statements, like hasAge, or canDance. It's not a problem when naming local ...
Kamil Bęben's user avatar
-1 votes
1 answer
331 views

How about instead of #define bool _Bool #define true 1 #define false 0 #define __bool_true_false_are_defined 1 We should have this: #define bool _Bool #define true (bool)1 #define false (bool)0 #...
user avatar
11 votes
2 answers
511 views

I have been writing tests for a lot of long if/else trees recently, and I'm finding it a little discouraging. I want to speak in concrete terms, so consider the following example (I'll write in Ruby ...
preferred_anon's user avatar
1 vote
8 answers
4k views

Most programmers (including me) believe that methods with a boolean flag parameter should be refactored into two methods without the flag parameter. Are there any use cases for a boolean parameter ...
CJ Dennis's user avatar
  • 669
40 votes
8 answers
11k views

For example, suppose I have a class, Member, which has a lastChangePasswordTime: class Member{ . . . constructor(){ this.lastChangePasswordTime=null, } } whose lastChangePasswordTime ...
ocomfd's user avatar
  • 5,760
5 votes
7 answers
4k views

I am recently studying computer science and I was introduced into Boolean algebra. It seems that Boolean algebra is used to simplify logic gates in hardware in order to make the circuit design minimal ...
themhz's user avatar
  • 169
5 votes
3 answers
9k views

For example, to store whether sound is on, I have a boolean originally named "isSoundOn": private boolean isSoundOn=true; however, the default value of boolean is false, but I want my application to ...
ocomfd's user avatar
  • 5,760
-1 votes
1 answer
80 views

In a boolean system, say you have a while loop going on. Then you might have this: if (just_did_x) { do_something() } To prevent it calling do_something() more than once, you might do: if (...
Lance Pollard's user avatar
0 votes
1 answer
199 views

Wondering if there is anything closely resembling data-binding but for boolean values / triggers. It seems like it could be related to Binary Decision Diagrams (BDDs), but they are precomputed rather ...
Lance Pollard's user avatar
12 votes
5 answers
4k views

To be a bit more clear, I'll state that I've spent lots of time with different languages. But until now it's been either it'll use it all the time or it doesn't support it at all. Now work has me ...
Kit Ramos's user avatar
  • 231
4 votes
2 answers
2k views

I'm developing an application with Python. I want to have a Boolean variable that represent whether something is buy or sell but I'm not sure how I should name it. Here are my current ideas: isBuy ...
tgwtdt's user avatar
  • 159
81 votes
9 answers
14k views

As noted by in the comments by @benjamin-gruenbaum this is called the Boolean trap: Say I have a function like this UpdateRow(var item, bool externalCall); and in my controller, that value for ...
Mario Garcia's user avatar
27 votes
8 answers
8k views

Lets say I am trying to describe my code in a technical meeting. First, I set the boolean foobar to true and Second, I set the boolean foobar to false seems a bit wordy. If foobar was toggled, I ...
Anon's user avatar
  • 3,649
3 votes
5 answers
8k views

I came across this issue at my second job interview. The technical interviewer said multiple times that booleans are not ok to be passed as parameters in methods, rather find another constructs (Enums)...
Adrian Muntean's user avatar
58 votes
8 answers
20k views

Is there an operator equivalent of nor? For example, my favorite color is neither green nor blue. And the code would be equivalent to: // example one if (color!="green" && color!="blue") { ...
1.21 gigawatts's user avatar
4 votes
4 answers
2k views

I was reading on this page about setting a flag in a loop and using it later. Most of the answers agreed that it's a code smell. One of the answers suggested refactoring the code by putting the loop ...
user avatar
39 votes
13 answers
14k views

According to Is it wrong to use a boolean parameter to determine behavior?, I know the importance of avoid using boolean parameters to determine a behaviour, eg: original version public void ...
ocomfd's user avatar
  • 5,760
11 votes
2 answers
11k views

I see size of boolean is not defined. Below are two statements I see at java primitive data size not precisely defined Further explanation says boolean represents one bit of information, but its "...
user3222249's user avatar
6 votes
8 answers
1k views

According to Is it wrong to use a boolean parameter to determine behavior?, I know it is bad: public void myFunction(boolean b){ if(b){ }else{ } } and it should have separate function: ...
ocomfd's user avatar
  • 5,760
2 votes
4 answers
5k views

I'm working on a little pet program in C where I have a game board that consists of a bunch of squares: typedef struct _square { bool checked; } Square; typedef struct _board { Square *...
tonysdg's user avatar
  • 131
2 votes
3 answers
577 views

I'm writing a reminder application where reminders can be shown or not for each day of the week (similar to Google Calendar). So I'd like to store the following in my SQLite database: Monday: True or ...
sunyata's user avatar
  • 477
3 votes
1 answer
225 views

The C# language has two "AND" operators when dealing with Boolean values, & and &&. (Leaving aside the bit-wise operators.) When the left-hand value is False, the difference between these ...
billpg's user avatar
  • 729
1 vote
1 answer
63 views

The goal is to take a binary space, say 64 bits, and make certain parts of it "valid" and certain parts "invalid", then increment, starting at 0, through that space, avoiding the invalid areas. Space ...
Not Really's user avatar
2 votes
1 answer
259 views

I have a table, let's call it Widgets, a Tags table with about 30 tags, a WidgetsTags table that joins each widget with any number of tags, and a table called LandingPages, the landing pages are for ...
Neil N's user avatar
  • 612
15 votes
2 answers
15k views

"0", as a string containing one character, is not something empty intuitively. Why does PHP treat it as FALSE when converted to a boolean, unlike other programming languages?
Michael Tsang's user avatar
5 votes
3 answers
834 views

If I have a function where I am operating on a specific offset within a string, and the exact location of this offset depends on a previous test within the function, is it "bad practice" or "ugly" to ...
Govind Parmar's user avatar
0 votes
0 answers
239 views

In building my classes, I have noticed that I have not been very consistent about naming my boolean returns. In Qt; I notice that many of their classes use the is prefix, but checking their coding ...
Anon's user avatar
  • 3,649
10 votes
2 answers
3k views

Nand is known as a 'universal' logic gate, because it allows you define all other boolean logic gates: not(x) = nand(x,x) and(x, y) = not(nand(x, y)) or(x, y) = nand(not(x), not(y)) nor(x, y) = not(...
Qqwy's user avatar
  • 4,947
2 votes
2 answers
3k views

Short Problem: How should I check if integers are undefined, just as I can check QStrings for having NULL values? Backstory: This is my coding style when I am trying to avoid overloading my ...
Anon's user avatar
  • 3,649
2 votes
1 answer
2k views

I am looking at A SAT-based Public Key Cryptography Scheme and got inspired to challenge myself to write an implementation of this Cryptography Scheme on Python. A part of the cipher encoding would ...
Kristina's user avatar
0 votes
3 answers
1k views

Why is it that some languages don't even have a boolean type (and uses a constant TRUE instead), but they have many other and modern types? Sometimes it can be trouble if you make a boolean and then ...
Niklas Rosencrantz's user avatar
-2 votes
2 answers
412 views

I'm currently in the process of setting up roles where there are regular users, admins, and super admins, each of which have special permissions. I deferred to this post on how to do so. It ...
Carl Edwards's user avatar
3 votes
4 answers
8k views

function haha($lol) { if($lol) { echo "plus"; } else { echo "minus"; } } haha(-1) echoes plus. Is it because PHP uses twos complement? Google search wasn't really helpful.
Vegan Sv's user avatar
  • 227
3 votes
2 answers
245 views

My first attempt at this question was too theoretical, so I've rewritten it with actual code. See the edit history if you care. Supposing this logic, "suffering" from the arrow anti-pattern: /** * ...
bishop's user avatar
  • 730
4 votes
5 answers
695 views

I found out that some languages like C don't have support for boolean variables and programmers use integers with values of 0 and 1 instead. Is there any specific reason why some languages moved away ...
Royce's user avatar
  • 49
-1 votes
1 answer
202 views

Modify the car painting example car.color = favoriteColor ||"black"; so that the car is painted with your favorite color if you have one; otherwise it is painted with the the color of your garage: ...
BreeA's user avatar
  • 11
10 votes
6 answers
5k views

I came across the following conditional in a program that I have taken over from another developer: if (obj.Performance <= LOW_PERFORMANCE) { obj.NeedsChange = true; } else { obj....
Zach Olivare's user avatar
-4 votes
3 answers
6k views

Unity3d PlayerPrefs only allow saving certain types - string, float, and int32. Since int is composed of 32 bits, it should be able to store 32 flags or a bool[] of length 32. So far, I've thought ...
JPtheK9's user avatar
  • 199
6 votes
3 answers
8k views

I'm trying to make a basic cache of a boolean value, and I did it like such: private Boolean _valueCache = null; private boolean getValue() { try { if (_valueCache == null) { // if cache ...
Ky -'s user avatar
  • 565
0 votes
1 answer
826 views

I've got a fairly large set of booleans I'm checking in javascript, and then using them to alter the state of a layout in my React app. The whole thing is unwieldy, difficult to read, inelegant, and ...
Kevin Whitaker's user avatar
3 votes
2 answers
5k views

I stumbled about a Cppcheck warning (an inconclusive one), that I mistakenly used & instead of &&: /// @param code identifies the command. Only the lower 16 bits of are being processed ...
Wolf's user avatar
  • 640
0 votes
3 answers
217 views

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)) { console....
airnet's user avatar
  • 111
0 votes
2 answers
4k views

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. ...
GermanShepherd's user avatar
2 votes
1 answer
265 views

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 a ...
Jack's user avatar
  • 131