What is your preferred logical pair: 1/0 Yes / No True / False?

  • When working with MySQL, I usually use the BOOLEAN type, which is equivalent to TINYINT (1) or 1/0
  • Most languages โ€‹โ€‹I work with are preferable to true / false.
  • When displaying forms, sometimes "Yes / No" makes sense
+3
sql naming-conventions project-planning
source share
7 answers
enum Bool { True, False, FileNotFound }; 

http://thedailywtf.com/Articles/What_Is_Truth_0x3f_.aspx

+24
source share

In the code: true / false.

In the user interface: Yes / No or OK / Cancel

+7
source share

true and false make much more sense to me, in the code - partly due to my acquaintance, I'm sure. I suspect I'm used to yes and no pretty quickly. 1 and 0 really don't work for me though.

Consider the expression

 age == 5 

This is a test for truth. Is the value of age 5? Yes it's true. Both "yes" and "no" would be good for me, but the idea is that the answer to the question "Is the value of age 5?" "1" seems pretty intuitive to me. Just because a typical binary representation of the truth does not mean that it is useful for higher abstraction.

+6
source share

Which is easier to read?

 while(true) {} while(yes) {} while(1) {} 

In most cases, I adhere to the rights.

+5
source share

Here are the rules that I live ...

Rule number 1

Use well-defined constants in the programming languages โ€‹โ€‹that you use to communicate with the CPU, i.e. true / false in most modern cases for boolean values. If the database offers a boolean type or some such equivalent, of course, it should be used.

Rule number 2

Interaction with users of your software using their preferred language and idiom, that is, Yes / No questions that should be asked by Yes / No (or, possibly, an alternative to No, for example Cancel).

Rule number 3

Uncertainty must be expressed in terms of volume, i.e. โ€œit dependsโ€, followed by the question โ€œabout what?โ€. I know developers who answer the question by copying and pasting almost every dependency they may need in every project code file, like the using statement. This is just careless, and please take care of the alphabetical, or at least the group namespace together.

When bool Just Is Not Enough

By the way, the interesting twist on this available in C # is Nullable;

You can write

 Nullable<bool> RespondToIritatingQuestion() { return new Nullable<bool>(); } 

OR

 bool? RespondToIritatingQuestionWithSytle() { return new bool?(); } 

and the questionnaire will have to evaluate your answer before even knowing what answer, if any, maybe ...

 bool? answer = RespondToIritatingQuestionWithStyle(); if (answer.HasValue) Trace.WriteLine("The bloke responded with " + answer.Value.ToString()); else Trace.WriteLine("The bloke responded with 'depends'."); 
+5
source share

1 or 0 for SQL. SQL has a boolean type for some reason. In addition, in very large databases, this can affect performance.

+2
source share

I use booleans for true / false fields in databases. Some people use ENUM('true', 'false') , but that is not my preference. For programming languages, I always use true / false, even if setting 0 or 1 will work. And if the form requires yes / no, I still use booleans to represent the values, but display them as strings that are more logical.

0
source share

All Articles