Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
@C0D4 who knows? If the returning method could know if the value is True or False if would not return NULL in the first place. There is no logical way to process NULL - except throwing an exception.
Casting it into False is as invalid as casting it into true. -
in Java you have two types of boolean.
- boolean (primitive) can be either true or false.
- Boolean (object, a boxed primitive) can be either TRUE, FALSE or null.
This in fact gets very handy! -
Depends on implementation IMO. A proper null is not a value, it's an indication of a lack of value. Kotlin handles it nicely: you have to allow nulls explicitly and then you have to deal with them explicitly. At the same time, Java's null is terrible.
-
ddephor45116yA boolean can never be NULL, it is always true or false.
If a NULL is converted to boolean, it usually evaluates to false. But if it can be NULL, it's not a boolean.
There is in fact something called Tri-State, which can have three states:
- True
- False
- Don't care
But Tri-States are usally used in electronics (high signal, low signal, high impedance), they are not common in programming languages. -
xewl41716yI reckon in MySQL that Bool is actually a tinyint(1) and should be casted in the code anyway. Though, I'm pretty sure, when you look for false values, you'd want to check for both NULL and 0 values when looking for false. (eg. I think it ignores the NULL values when looking for "<1")
-
C0D4681456y@xewl in mysql Null is always treated as Null.
Any arithmetic operation will result in null.
That’s why we have <=> for null safe comparisons. -
C0D4681456y@UnmutableToday in loosely typed languages null will become false.
If(null == true) # false
Strict/strong type languages throw exceptions for null pointers which is the correct behaviour.
@xewl
https://dev.mysql.com/doc/refman/...
This thing has made life easier when working with nulls -
nah, I mean if the column is non-nullable (ergo no nulls will be ever there) and you're checking whether column `<> 0`
null values -- N/A (because of the constraint)
0 <> 0 == false -- there you go
1 <> 0 , 500 <> 0 , -436356 <> 0 == true -- because anything but 0 is not 0 :) -
Not an expert but in C# you also have nullable types which allows you to have Nullable<bool>. You can also declare them as bool? (with the question mark). We used that kind of variable because some fields in the database were neither true nor false, they were null. And this would avoid giving us an error when getting the value of the bool.
-
A boolean variable is always true of false. If it is null, this means that the boolean variable doesn't exist.
Related Rants
Doesn't the existence of NULL in a language mean, that there cannot be a boolean type? Because a bool is defined by the fact, that it can have two possible values. Having NULL changes that.
Without NULL a variable of the type bool could be True or False, two possible values. With NULL is can be True, False or NULL, three possible values.
I hate NULL.
question
null