Efficient coding considered harmful?

Doug Gwyn gwyn at smoke.BRL.MIL
Sat Nov 12 14:47:26 AEST 1988


In article <771 at wsccs.UUCP> dharvey at wsccs.UUCP (David Harvey) writes:
>... who would fail me for the following code:
>if( ! something) {
>	++j;
>but would pass me with flying colors for the following:
>if ( something != 0)
>	{
>		j = j + 1;

If "something" is conceptually Boolean, then even your instructor
should think !something is preferable to something==0 (note the bug
fix) since his favorite languages have explicit Boolean NOT operators.
On the other hand, if "something" is conceptually arithmetic, then
something==0 is stylistically preferable to !something.

++ is obviously thought of as a unary increment operator, which those
other langauges don't have (which is probably why your instructor is
not comfortable with the idea).

>declaration of variables within the function parentheses will
>provide the 'protection' that Pascal lovers want only if the
>compiler can compile both the caller and callee at the same time.
>Or the linker must be more sophisticated, using information that
>is generated by the compiler.  How will it be handled folks?

I see you don't understand how function prototypes work.
(Perhaps this is due to your instructors also?)
The compiler can (indeed, must) check function arguments and
parameters against the corresponding prototype when it is in
scope.  Typically this occurs when a prototype declaration is
supplied in an "interface" header file that is #included near
the beginning of each source file that refers to things defined
or declared by that header.

>But then we could always #include C code files, which is exactly
>what one of the afore-mentioned teachers required of beginning C
>students!

Obviously he has a Pascal mind-set.

One of C's important features is the support for separate
compilation.  ANSI C's function prototypes in no way weaken
this; in fact they better support it.  No linker support is
required beyond that required by "K&R C".

-----

My advice to you as a student is to learn proper C usage from
books by people like Brian Kernighan and Tom Plum.  (There are
other good authors of C books too, as well as scores of bad
ones.  I just picked a couple of the best.)  Give your
instructors whatever silly crap they demand and don't waste
time worrying about it or trying to educate your instructors.
School serves two main practical purposes: it gets you a scrap
of sheepskin that helps you get a desirable job, and it
potentially helps you learn how to learn under your own steam.
The actual data content of your courses won't usually do you
much good later in life, but general methods of gathering and
evaluating information remain valid "forever".



More information about the Comp.lang.c mailing list