Re: About some understanding from a book
- From: "Peter Duniho" <NpOeStPeAdM@xxxxxxxxxxxxxxxx>
- Date: Thu, 12 Jun 2008 17:00:54 -0700
On Thu, 12 Jun 2008 14:27:29 -0700, Chris Jobson <chris.jobson@xxxxxxxxxxxxxx> wrote:
[...] (you're required to define
both, but I expect you'd generally just have one call the other and invert
the result. Any other design could start to get confusing.
I just took a look at the spec out of interest, and it appears that the
"true" operator does not necessarily have to return the inverse of the
"false" operator.
Sure, that's what I implied, by writing "generally" rather than "this is always how it'd be done" (I forgot to close my paren, but whatever :) ). My point being that doing it in some other way could be confusing. That said, the DB example you give seems reasonable (I didn't notice it when I was looking at the spec). BUT! I by "reasonable" I just mean "justified". I still think the design itself would be more confusing, even in that example.
Section 11.4.2 of the spec shows a 3-valued type (database
boolean, which can be true, false or null) where operator true means
"definitely true" and operator false means "definitely false". Thus if the
value is null both operators return false. (I don't claim to understand the
logic behind this, but I have hopes that if I read it through a few more
times it will start to make sense!)
If I may:
The point would be that code that cared about "definitely true" would check for "true"-ness, while code that cared about "definitely false" would check for "false"-ness. I would guess that in most cases, it's not so much that you'd check for "false" from both operators, but that you'd have different code keying off of "true" results from either.
That said, that brings me back to my previous supposition about how the compiler would actually use those operators. In particular, in my mind you'd write code like:
if (myClass)
{
// something we do only when it's "definitely true"
}
if (!myClass)
{
// something we do only when it's "definitely false"
}
But this would rely on the compiler _always_ using the ! operator as an indicator to use the "false" operator instead of the "true" operator. I'd have to go back and look at the spec, but unless it _specifically_ say that the compiler is required to do this, then it's entirely possible a C# compiler could just ignore the "false" operator and just always invert the result of the "true" operator when faced with the ! operator.
In that scenario, the DB example would break, unless the compiler is mandated to behave in a specific way.
Maybe if I get interested enough, later I'll look at what the spec says about that. :)
Pete
.
- Follow-Ups:
- Re: About some understanding from a book
- From: Chris Jobson
- Re: About some understanding from a book
- References:
- About some understanding from a book
- From: Tony Johansson
- Re: About some understanding from a book
- From: qglyirnyfgfo
- Re: About some understanding from a book
- From: Peter Duniho
- Re: About some understanding from a book
- From: Chris Jobson
- About some understanding from a book
- Prev by Date: Content Path with a One Solution Two Project setup
- Next by Date: Re: Hi all
- Previous by thread: Re: About some understanding from a book
- Next by thread: Re: About some understanding from a book
- Index(es):
Relevant Pages
|