Questions tagged [boolean]
The boolean tag has no summary.
70 questions
7 votes
8 answers
942 views
Why is "one function do more than one thing" a disadvantage of "boolean parameter", but not in "polymorphism"?
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: ...
3 votes
2 answers
6k views
how to name functions that return booleans
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? ...
4 votes
5 answers
419 views
Using dedicated functions for opposites/inverse
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 ...
1 vote
6 answers
4k views
Naming boolean fields in classes
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 ...
11 votes
2 answers
509 views
Is it possible to test if/else trees properly without coding to the implementation?
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 ...
40 votes
8 answers
11k views
Is a new Boolean field better than a null reference when a value can be meaningfully absent?
For example, suppose I have a class, Member, which has a lastChangePasswordTime: class Member{ . . . constructor(){ this.lastChangePasswordTime=null, } } whose lastChangePasswordTime ...
5 votes
3 answers
9k views
Is it necessary for a boolean to be "false" by default?
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 ...
0 votes
1 answer
198 views
Data-binding for Boolean values
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 ...