Re: Paying developers to get features faster

From: james (fishbowl_at_conservatory.com)
Date: 01/26/04


Date: Mon, 26 Jan 2004 04:36:29 GMT

In article <js91vb.3u5.ln@news.it.uc3m.es>,
P.T. Breuer <ptb@oboe.it.uc3m.es> wrote:

>And mine with yours. When you mean to use a boolean, use it like a
>boolean:
>
> if (has_escaped_from_zoo)
>
>not
>
> if (has_escaped_from_zoo != 0)

But I do totally agree with that. Even if your language doesn't
explicitly support a bool type, if you have a value that's going to be
treated as a bool, you should stick to it. It shouldn't be an int
in one line, and then magically become a bool when it happens to be
convenient to compare it to zero.

>> I find if(NULL == var) to not only be easier to read, but I also regard
>
>You should probably never read it. It means that you are using a
>pointer instead of a boolean.

That's a very good point, but I do know the difference between the
pointer comparison and the boolean result of the pointer comparison.

>However, if you really meant to test the condition that the pointer is
>null, which is an error condition, then you would indeed write
>
> if (var == NULL)

The origin of this argument is based on the fact that it is possible to
write ( var = NULL ) and spend too long tracking it down. Writing it
as (NULL = var) should cause a compile-time error, and should certainly
be easier to find. The words "proper tools" came up. I started
learning this trade in the 1970s so these habits are pretty deep-seated.

>(though I'd probably always write !var since I would always use a
>pointer also in the sense of the predicate

Well, if the language is guaranteed to evaluate the NULL pointer as 0,
that's fine. Certain very popular languages do not allow you dto do
that.

>> it as a sign of experience and professionalism when I see it in code.
>> My peers agree.
>
>But they are wrong. Probably because they are poor logicians.

It's a matter of opinion. There is no "right" and "wrong", and while I
may not be a mental giant myself, I resent that you have just called my
peers "poor logicians." You don't even know who you are insulting!



Relevant Pages

  • Re: Paying developers to get features faster
    ... treated as a bool, ... pointer comparison and the boolean result of the pointer comparison. ... Well, if the language is guaranteed to evaluate the NULL pointer as 0, ...
    (comp.os.linux.development.system)
  • Re: Paying developers to get features faster
    ... treated as a bool, ... pointer comparison and the boolean result of the pointer comparison. ... Well, if the language is guaranteed to evaluate the NULL pointer as 0, ...
    (comp.os.linux.security)
  • Re: Paying developers to get features faster
    ... treated as a bool, ... pointer comparison and the boolean result of the pointer comparison. ... Well, if the language is guaranteed to evaluate the NULL pointer as 0, ...
    (comp.os.linux.misc)
  • Re: Question on LSP
    ... We are talking about sibling subtypes in an existing tree. ... But that is not known until the Object Reference type is instantiated; yet the semantics of Object Reference must exist in the language meta-model prior to instantiation. ... A pointer points only to an object and messages are sent to objects. ...
    (comp.object)
  • Pointers and Teaching C++ [was Re: A little disappointed]
    ... like Java where *many* facilities such as raw pointer access / manipulation ... are removed in order to create a 'safer' language and stop programmers ... then it is probably wiser to teach programming using ... pointer access / manipulation is not a 'high level language'. ...
    (alt.comp.lang.learn.c-cpp)