On Jun 26, 2011, at 8:38 PM, Campbell Barton wrote:
On Sun, Jun 26, 2011 at 9:02 PM, Johan Engelen <jbc.engelen@...2592...> wrote:
On 26-6-2011 0:22, Jon Cruz wrote:
One is with the use of "NULL". That is more of a C macro that in C++ has be replaced with the simple use of "0". I've looked into this point with coworkers and others at various points, and can try to dig up more details if you need them.
I think I like the use of "NULL" much more than "0", as it more clearly indicates the type.
Consider this code example of initializing variables: box->persp_href = 0; compared with box->persp_href = NULL;
I think the second version is clearer about what is being done. (the first looks like the number of refs is set to zero, instead of initializing a ref pointer
Ciao, Johan
Ah, thought you were saying _not_ to use NULL in C++, agree with you its easier to understand. the source code checker 'sparse' can find these cases though its C only.
What I've seen is that after a bit with either, the legibility is about as good. That is, when I've worked on code that used '0' instead of 'NULL', the '0' became more the readable one over time. It does get to be a bit subjective (although there are edge cases where NULL does not work as well in C++). I think much of preferring NULL comes down to "what you're used to".
Another problem with the legibility of using '0' instead of 'NULL' can come from those familiar only with C coding, and who therefore don't expect that '0' can be a valid pointer.
Now on the other hand Johan used an example that exposed a *different* problem with the code, IMHO. He cited a good case of potential confusion... however I would say that the problem is in the naming, not in the value being assigned. That is, if one is expecting the variable named "_href" to contain a count, then there is a naming problem. *If* something were to be a count, I would like to see a good self-documenting variable name such as "_hrefCount" or "_refCount". If we have clear names like that, then one reading the code would not expect "_href" to contain a count of anything, since it did not say it did.