On Wed, Apr 8, 2015 at 12:17 PM, Ron W <ronw.m...@gmail.com> wrote:

> On Wed, Apr 8, 2015 at 1:58 PM, Scott Robison <sc...@casaderobison.com>
> wrote:
>
>> Or whatever your team dictates. :)
>>
>
> In our case, we are required to follow "industry guidelines", except where
> compelling technical issues require a deviation. And such deviations must
> be documented. Also, use of NULL is considered more indicative of the
> intent, therefore, more readable.
>

I agree the rationale for using it is valid, and particularly the idea that
"if(p!=NULL)" works whether or not your environment is standards compliant.
So I'm not saying you're wrong to use that particular construct, just
observing that 0 is not wrong in a standards compliant compiler as it will
"do the right thing". There are many ways to do the same task. Each has its
pros & cons.

I live mainly in C++ land, so I avoid NULL. I do like the nullptr constant
of C++11 and later, since there is no way for it to be accidentally
converted to an integer. I happen to like the "if(p)" syntax as succinct
terminology for "if(p is valid)" (or "if(!p)" for "if(p is not valid)"),
though. None of them are perfect, and good reasons can be given for any of
them IMO.

Recently I've been working in C++ code where the programmer liked to use
"if(TRUE==someBOOL)" which I hate on so many levels:

1. If you have to use BOOL due to the Windows API, fine, but limit your use
of BOOL to that, use bool the rest of the time.
1a. Same for TRUE & FALSE vs true & false.
2. I dislike Yoda conditionals of the form "constant op variable". I
realize there are reasons why people use them, to avoid accidental
assignment in a conditional, but the modern compilers I work with diagnose
these problems for me so that I can have clearer code without the risk of
accidental assignment.
3. If someBOOL returns a true value that happens to not be exactly equal to
1 (the definition of TRUE) then the statement will fail when perhaps maybe
it shouldn't have?
3a. If you are really depending on the value to be 0 & 1 vs zero & not
zero, don't call it a BOOL.
4. I dislike "someBOOL op constant" statements. Just say "someBOOL" or
"!someBOOL".

But I digress. Sorry. Carry on.

SDR
_______________________________________________
fossil-users mailing list
fossil-users@lists.fossil-scm.org
http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users

Reply via email to