boolean

Objective C - Which syntax?

What syntax do you think is better/more readable? if(!myViewController.view.superview) or: if(myViewController.view.superview == nil) Thanks!! ...

Ways to indicate a BOOL wrapper?

In Objective-C, are there any ways to indicate that an NSNumber* should actually be a BOOL? Right now my code looks like: NSNumber *audio; // BOOL wrapper Without the comment, it is not immediately obvious that *audio is a boolean value. My first thought was to try typedef NSNumber* BOOL; but this gave a compiler error apparently ...

boolean parameters -- do they smell?

I just found a bug caused by a boolean parameter... the caller thought it was controlling one thing but it was really controlling something else. So do boolean parameters smell in general? Personally, I don't feel comfortable when I see them. I mean: DoSomething(false); What the heck am I supposed to think when I read something lik...

Strange C++ boolean casting behaviour (true!=true)

Just read on an internal university thread: #include <iostream> using namespace std; union zt { bool b; int i; }; int main() { zt w; bool a,b; a=1; b=2; cerr<<(bool)2<<static_cast<bool>(2)<<endl; //11 cerr<<a<<b<<(a==b)<<endl; //111 w.i=2; int q=w.b; cerr<<(bool)q<<...

Check if model instance falls within named_scope in rails

Assume I have a named scope: class Foo < ActiveRecord::Base named_scope :bar, :conditions => 'some_field = 1' end This works great for queries and I have a bunch of useful named_scopes defined. What I would like is to be able to do this: f = Foo.find(:first) f.some_field = 1 f.is_bar? #=> true The '.bar?' method will simply ret...

How to do true==false or true!=true in your language?

Booleans seem to be the most primitive building blocks of programming languages, because they can actually take only two (or in some cases three) "singleton" values: true, false (and sometimes undeterminded/null) But it seems that sometimes language design might allow someone to write code where actually "true is false" or "true is not ...

What's the difference between boolean and Boolean in Java?

I would like to understand the difference between the Boolean and boolean types in Java, specifically as they relate to GWT. I know that methods are not supported but I want more info if it is available. ...

xsd:boolean element type accept "true" but not "True". How can I make it accept it?

I am using xmllint --schema option to validate my XML that looks like this <XML> <Active>True</Active> </XML> In my schema file, I have following line that describes Active element. <xsd:element name="Active" type="xsd:boolean" /> When I run xmllint, I get error messages that says /tmp/schema_validation.xml:73: element Activ...

Why use !! when converting int to bool?

What can be a reason for converting an integer to a boolean in this way? bool booleanValue = !!integerValue; instead of just bool booleanValue = integerValue; All I know is that in VC++7 the latter will cause C4800 warning and the former will not. Is there any other difference between the two? ...

How to make a logical boolean parser for text input ?

Hello friends, I need to make a parser to be able to extract logical structure from a text input in order to construct a query for some web service. I tried to use regular expressions but it gets really complicated to handle imbrication logic, so I decided to ask for help, maybe I am doing it the wrong way. ex: ( (foo1 and bar) or (f...

To have boolean type in Postgres for PHP

I can't believe that the following statement seems to be still true So, I switched to integers and 0 or 1 works fine, but it is stupid, that the database system has boolean variables of a smaller size, but I should use integers for boolean values! How do you use boolean datatype with Postgres / PHP? In other words, Is the only way t...

What is an efficient algorithm to create all possible combinations?

Let's say there's n amount of entries, each of whom can take the value of 0 or 1. That means there's 2^n possible combinations of those entries. The number of entries can vary from 1 to 6. How can you create each possible combination as a sequence of numbers (i.e. for n = 2: 00, 01, 10, 11), without resorting to a thousand IFs? ...

error: property 'myBoolVariableName' with 'retain' attribute must be of object type

I have a BOOL value inside my @interface definition in my .h file. Here it is below. It has the same problem whether it's a pointer or not. @interface myCustomViewController : UIViewController <UIWebViewDelegate> { { //...more iboutlets defined above BOOL *myBoolVariableName; } When I compile, I get "error: property 'myBoolVariabl...

Handling more than 2 possible returned values?

When a function returns a boolean you can easily if (task()){ // it worked! }else{ // it failed. } But when it returns multiple different values it gets messier var status = task(); if (status == 1){ // hmm }else if (status == 2){ // hmmmmm }else if (status == 3){ // hmmmmmmmm! } ..is there a neater way of handling ...

How to determine the result of a logical operator on nullable booleans?

In C#, for example, when I compare two nullable booleans (bool?) I get the following results : true & null = null false & null = false true | null = true false | null = null The issue is that I couldn't understand how those results come, what's the rule which I can use to determine the result of a logical operator on two booleans, whe...

ILGenerator: How to add boolean to the stack

Here is the way I can put float value to the stack(in C#): ILGenerator gen = method.GetILGenerator(); gen.Emit(OpCodes.Ldc_R4, (float)12.5); How can I put boolean value to the stack by using Emit method? ...

Language features: optimizing booleans to flags + bitmasks.

I'm writing a programming language, and when I came across this question, my immediate thought was that languages should optimize booleans into bit flags for the programmer. This would keep all the benefits of speed and efficient memory usage while removing the burden of maintenance and the possibilities for errors caused by the more co...

Cast bool to T where T is int

How can I make this function reliably cast sourceValue to type T where sourceValue is bool and T is int? public static T ConvertTo<T>(Object sourceValue) { // IF IS OF THE SAME TYPE --> RETURN IMMEDIATELY if (sourceValue is T) return (T) sourceValue; var val = ConvertTo(sourceValue, typeof (T)); return (T) val; } Curren...

Ruby on Rails Boolean Form

Hey, How can I pass a boolean value in a form to a controller without the user being able to see or edit it? I'm assuming hidden_field is used for this, but how can I then assign a value to the variable? Thanks for the help -Pat ...

How to optimize boolean operation?

I have two RadioButtons: r1 and r2. I have to enable both on Enabled = true and disable only unchecked on Enabled = false public bool Enabled { set { if(value) { r1.Enabled = value; // true r2.Enabled = value; } else { if(!r1.Checked) { r1.Enabled = value; // false if not checked ...