On Mon, 20 Nov 2006 14:56:56 -0500, Doug Arnott
<da*********@rogers.comwrote:
>http://www.cs.rutgers.edu/~pxk/rutge...pdf/Cstyle.pdf
has an example at the end of the document of an example of
an alternative implementation of interest to me. In this
example, the document provides an alternative implementation
to the if-else sequence of using strcmp to match a set of
strings. Such an example makes me think about the pro's and
con's of the different implementations.
The example provided does two things:
It replaces a sequence of if (strcmp(str_var,str_const_i))
statements with a for loop containing if (strcmp(str_var,
str_const_ptr[i])). While the resulting code may be more compact, in
general the exact same number of calls to strcmp will be executed so
performance will probably be a little worse (looping and indexing are
not free).
It requires that all the functions to be called either have the
same prototype (which may not be possible) or you omit prototypes for
the functions (which is very undesirable).
He also has what I consider some strange ideas about acceptable style.
He likes
if (...){
...
}else{
...
}
and declares
if (...)
{
...
}
unacceptable.
I consider the that else style an abomination and code the second
because I like my braces to line up.
He also claims that a short explanation of a program's function and
prompts for input are overly verbose since everyone knows that a
program named fact can have no other purpose that to calculate
factorials.
The fact that his examples will not compile (e.g., fprintf with only
two arguments) does not improve his credibility.
>
I am looking for more of such examples. If you have any
examples to share, then I would like to see them. Perhaps
there is a website or book which contains such examples, if
so, then please provide the applicable information.
Thanks,
Doug
Remove del for email