boolean

Difference between "if x" and "if x is not None"

It appears that "if x" is almost like short-hand for the longer "if x is not None" syntax. Are they functionally identical or are there cases where for a given value of x the two would evaluate differently? I would assume the behavior should also be identical across Python implementations - but if there are subtle differences it would b...

What's the most concise way to get the inverse of a Java boolean value?

If you have a boolean variable: boolean myBool = true; I could get the inverse of this with an if/else clause: if (myBool == true) myBool = false; else myBool = true; Is there a more concise way to do this? ...

Boolean.hashCode()

Now I see how to implement a method hashCode() for the Boolean object: public int hashCode() { return value ? 1231 : 1237; } And I wonder why it returns a values 1231 or 1237, why not something else? ...

Why does Perl use the empty string to represent the boolean false value?

When evaluating an expression in a scalar (boolean) context, Perl uses the explicit value 1 as a result if the expression evaluates to true and the empty string if the expression evaluates to false. I'm curious why Perl uses the empty string to represent boolean false value and not 0 which seems more intuitive. Note that I'm not concern...

using Boolean Object

i'm having issues trying to get the result I wish. Basically what I want to do is have a Boolean object which will allow me to have 3 choices, if a mailer is old i want it to be set to false (meaning does not contain "mapQ.cmd" and "add-coid.cmd" file) if a mailer is new I want it to set to true (if it is new it will contain "mapQ.cmd" ...

Boolean Table in VB.Net - Select Case, If-Else, or Something else?

Hey all, I'm looking to simplify the handling of a three-item Boolean expression. "Select Case" doesn't seem offer a solution for triple values, and the If statement seems a bit much. It'll work the way I coded it, but if you have any ideas on how to simplify this, I'd appreciate your insights. If not, I hope this snippet can save someon...

How can I add a Boolean field to MySQL DB?

It seams I should use tinyin(); but I dont know how to implement it? The question is what is your recommendation if I need to have a boolean field in MySQL DB and modify it´s value with PHP. Thanks in advance! Trufa ...

how can I return the index of an object in a 2 dimensional array?

I am working with a 2-D array of nullable booleans bool?[,]. I am trying to write a method that will cycle through its elements 1 at a time starting at the top, and for each index that is null, it will return the index. Here is what I have so far: public ITicTacToe.Point Turn(bool player, ITicTacToe.T3Board game) { foreach (bool? b...

can the safe bool idiom be implemented without having to derive from a safe_bool class?

Is there a trick to get the safe bool idiom completely working without having to derive from a class that does the actual implementation? With 'completely working', I mean the class having an operator allowing it to be tested as if it were a boolean but in a safe way: MyTestableClass a; MyOtherTestableClass b; //this has to work if( ...

C : is there "lazy evaluation" when using && operator, as in C++ ?

Hello, i would like to know if this looks correct : while((next !=NULL) && (strcmp(next->name, some_string) < 0) { //some process } i mean, if next is NULL, then the second part of the expression won't be ever tested by the compiler ? i have heard that in C++ it's the case (but i'm not even sure of it). Can someone confirm me th...

Custom Editor for a Boolean Property in a PropertyGrid (C#)

Hi, I want to assign a custom editor to a boolean property in a PropertyGrid. I'm using the standard propertygrid (from namespace System.Windows.Forms). It is possible to assign custom editors to properties using the UITypeEditor class. However, as far as I can see, it is not possible to use it for a boolean property. I've tried to so...

Casting boolean to Boolean in java

i have a code as public class BooleanTest { public BooleanTest() { super(); } public static void main(String args[]){ BooleanTest bt = new BooleanTest(); bt.doProcess(); } private boolean method() { return false; } private void doProcess() { Boolean obj = (Boolean)method...

Method with boolean return - if else vs. if

Take for example the following two statements: if (booleanVariable) { doSomething(); return true; } else { return false; } and if (booleanVariable) { doSomething(); return true; } return false; Which one would be preferred? They both return the same result in the end. Any reason one would be better to use than the ot...

boolean algebra - theorems

I have a homework question "Show the following is true using theorems. State which theorem you use at each step." This is just one of many problems I have! So, if you can help me with this one problem than I can apply what I learn to finish the rest. I don't want a handout; I just don't know where to start or what to do. I have looked t...

Comparing objects memory address, Java

Robot r1,r2,r3; r1=new Robot("Huey",2,3); r2=new Robot("Louie",5,4); r3=new Robot("Louie",5,4); r1=r2; r2=r3; r3=r1; System.out.print(r1==r2); So this program prints false, but I thought it would print true. Its asking if the memory address of r1 is the same as r2. Well r1 is set to equal r2, then r2 is changed to r3, but that shouldn'...

CS0019 Operator cannot be applied to operands of type 'bool' and 'int'

This program is in response to the assignment: "Create a method named Sum()that accepts any number of integer parameters and displays their sum. Write a Main()method that demonstrates the Sum()method works correctly when passed one, three, five, or an array of 10 integers. Save the program as UsingSum.cs." from Microsoft® Visual C#® 2...

Bounding box boolean subtraction?

What's the best or an efficient method for subtracting a bounding box from another bounding box (I.e. Creating n bounding boxes from a bounding box Boolean subtraction)? Ideally the resulting bounding boxes are as square as possible so that there are limited 'shard' (I.e. 1width, 1height, 100depth). ...

Booleans in grails aren't persisted?

Hello, I'm developing a small application on Grails 1.3.5 and I run into this very strange problem. My domain classes feature some boolean typed fields. None of these fields is persisted when creating a new instance (and saving it of course). For example, I have this domain class "Employee", defined as follows (simplified): class Emp...

Pythonic Boolean Conversion

I'm writing a module to act on data being sent to a database from Python. Since boolean is not a SQL datatype, those values have to be converted to some pre-defined value. I decided while defining the tables that I would use 'T' and 'F' in a varchar(1) field as my Boolean stand in. In attempting to make this conversion while being pro...

Java value of if statements

In Java can I return a boolean value with the following: public boolean areBothEven(int i, int j) { return (i%2 == 0 && j%2 == 0); } Or do I need to surround the statement with an if and then return true and false appropriately? ...