Derek Parnell wrote:
On Thu, 04 Jun 2009 10:06:45 +0300, Yigal Chripun wrote:

Andrei Alexandrescu wrote:
Yigal Chripun wrote:
your abstraction inversion example doesn't apply here. The problem I see is the narrowing implicit cast, i.e. int values behave like booleans. I have no problem with the reverse which is what your example is about.
An int does not convert to bool implicitly. An int can be tested with "if", which is a different thing.

Andrei
that is an implicit cast.
what I'm saying is that:

  int a = .. ;
  if (a) { .. }

this should be a compiler error IMO.

I'm not agreeing with you, Yigal.

I think that the idiom you described is not equivalent to
   if (a == TRUE) { .. }

but really
   if (a != 0) { .. }

when 'a' is an integer of any size or sign.
This should *not* be a compiler error as it is a convenient shorthand for
some coders. Personally, I try not to code this idiom because I find it
misleading in terms of self documentation ... but then I'm against using
goto as well ;-)



I don't see how we disagree since you say yourself that you try to avoid this idiom and find it misleading in terms of documentation. which I agree with. yes, it does save a few key strokes but as I said before, that's a really bad optimization since code is read much more often than it's written and readability is much more important than saving a few key strokes.

I also agree about goto. there are very rare cases where it is useful but outside those goto is a bad bad thing to use.

Reply via email to