things people should stop doing
Aug. 14th, 2009 09:09 pmif (constant == variable)
if (pointer != 0)
if (pointer != NULL)
if (boolean == true)
}
else {
fprintf(stdout, ...);
printf("%s", variable);
printf("string with no substitutions");
printf("\n"); // or any other single character
no subject
Date: 2009-08-15 06:40 am (UTC)no subject
Date: 2009-08-15 11:10 pm (UTC)I'd be quite a bit more dogmatic about this if puts() didn't tack on a newline. But it does. Bleh.
no subject
Date: 2009-08-15 11:10 pm (UTC)no subject
Date: 2009-08-15 09:09 am (UTC)if( 4 = variable ) { ... }And as for doing an fprintf to stdout, I've done that when I previously had code printing to stderr, but went through and changed it. Though I suppose a regexp could have replaced the fprintf with a printf...
no subject
Date: 2009-08-15 11:17 pm (UTC)The compiler should be complaining about "if (variable = 4)", and I find that I basically never miss one of those when reading, anyway.
fprintf(stdout,...) as a lazy man's conversion from fprintf(stderr,...) makes a lot of sense in the context of the code that prompted the original post; although what really bugged me about that was it was an inconsistent mishmosh of both.
no subject
Date: 2009-08-15 09:27 am (UTC)(In particular, I'd hesitate to deprecate printf("%s", variable) when its nearest cousin -- printf(variable) -- is so very nasty. Also, printf("%s", variable) gives you protection when variable may be NULL.)
no subject
Date: 2009-08-15 11:22 pm (UTC)no subject
Date: 2009-08-15 01:33 pm (UTC)The rest I don't quite get.
I assume the 5th is in reference to this specific brace placement, but I'm not quite sure I see your point.
On the last, is the idea s/printf("\n")/putchar('\n')/? It seems better to me to always use printf here, so that when you suddenly need '\n\n' the code rewriting is minimal. (Of course generally I would say: don't use printf for anything).
no subject
Date: 2009-08-15 11:21 pm (UTC)Yeah, on the last few, the idea is there are more efficient ways to write it. I don't think there's anything wrong with printf() when you actually need formatting, but when you don't (and the speed matters) you really want to be using fputs() and putchar().