While I think comments this late in the process will be ignored or
postponed for later, you really should address these concerns directly
to Microsoft.
<snip>
> Primary comment...
> 4) **(NULL-valued value types should be treated as ZERO, or FALSE for
> purposes of mathematic and logical operations!) -- This gives people an
> intuitive understanding of the program behavior and prevents the code from
> resulting in values that will make other code crash.
I don't like that at all. NULL usually means "unknown value" or "value
not specified", something which might come in handy when you are
recording data from a user in a database. What typically happens if you
drop NULL is that you pick one value as a "magic value" that means "the
user did not specify this value", and that effectively removes that
value as something that is valid. In other words, if the user types in 0
you suddenly don't know if the user left the field empty or if he typed
in 0, something which will be important for a lot of applications. In
cases where the value is used to refer to an object in a different table
this might be crucial because the database will typically not allow you
to refer to non-existant rows. In such a case you end up adding
dummy-rows to tables so that you can use 0 as a reference and not have
the database engine balk at your database updates.
> I) Comparative operators return FALSE if either operand is NULL.
> **(The comparative and mathematical operators should treat NULL as ZERO)
Again, since this meaning of NULL typically comes from the database
world where NULL means "unknown", not even two NULL values are
considered to be equal.
> II) Bitwise binary operations & and | are overloaded on the Bool type to
> serve as boolean logical operations with NULL as a ternary value...
> **(NULL should be treated as FALSE and work accordingly in all comparative
> operators).
Again, see above.
> Here is the corresponding truth table for the & and | operators on the bool?
> (that is, nullable bool) datatype:
<snip table>
> This makes nullable types dangerous to use in expressions, because they'll
> resolve to non-intuitive null values that will make the code crash.
It'll only make your code crash if you're using nullable boolean types
and don't cater for a NULL result.
>
> For example:
> true & null == null
> false & null == false
>
> Consider looking for the lowest int? in a collection of int? (nullable int)...
>
> foreach(int? n in collection) {
> if(n < curr) curr = n;
> }
>
> Not only would that code crash if collection==null, but it would lock onto
> NULL as the lowest value (if curr was initially NULL) because the comparative
> always returns FALSE when NULL is in an operand.
In this loop you're effectively not catering for NULL so again, this is
a bug in your code.
> Moreover, it yields non-intuitive and asymetrical behavior... Consider
> looking for the maximum int? in a collection:
>
> foreach(int? n in collection) {
> if(n > curr) curr = n;
> }
>
> Again, this finds NULL as the maximum value if curr is initially NULL.
>
> Okay, that might seem a contrived example. Hopefully you see the point.
I think you'll find that adding support for nullable types in your
software will require more than just adding a few question marks here
and there, it will require more extensive coding to support it.
foreach (int? n in collection) {
if (n > curr && n != null) curr = n;
}
this does not solve the problem of picking the first value, so something
like:
foreach (int? n in collection) {
if (n != null) {
if (curr == null || n > curr) curr = n;
}
}
--
Lasse Vågsæther Karlsen
http://www.vkarlsen.no/
private.php?do=newpm&u=
PGP KeyID: 0x2A42A1C2