Re: Malcolm's new book - Chapter 1 review
- From: "Malcolm McLean" <regniztar@xxxxxxxxxxxxxx>
- Date: Tue, 7 Aug 2007 00:17:02 +0100
"Eric Sosman" <Eric.Sosman@xxxxxxx> wrote in message news:1186440511.431078@xxxxxxxxxxx
Malcolm McLean wrote On 08/06/07 15:55,:The non-conforming implementation is an example of the book's style. It is not written in C that happens to conform to the standards of the day, but in C which I expect to still compile and work in a hundred years' time.
The book begins with a non-conforming implementation of
strlen(). It's kind enough to point out the nonconformity,
and goes on to provide a conforming replacement -- but one
wonders what purpose the bogus version serves, other than
to add thickness to the book.
The book's implementation of mystrdup() compels a C99You repeat this several times. What you mean is that the function bodies are given without headers. As you delve into deeper chapters you will soon see why this is - text interspersed with code means that the headers make too much visual mess without adding enough information content to justify inclusion.
compiler to emit diagnostics.
The problem is that by saying "a C99 compiler is compelled to emit diagnostics" rather than "I think it would have been better to include headers and prototypes" you really disqualify yourself as an objective commentator.
At about this point, the text draws attention to someThe convention applies for the whole book. "answer" isn't absolutely uniform, but it is my normal choice for a variable to hold a return value.
coding conventions. Among them: the use of the identifier
`answer' to hold a function's return value. Oddly enough,
this mention is the last appearance of "answer" in the
chapter; the rest of the functions do not follow the
stated convention.
Exactly. If you are doing very advanced programming then either you have to be brillinat and encyclopedic, or you have to use code you don't understand. Not an ideal situation, but it is very often necessary to do that.
There follows a peculiarity: A day-of-the-week function
that the author confesses he does not understand. The code
was "lifted from the net," says the book, but does not say
whether it was lifted from a reliable or from an unreliable
source. The text says it's all right to use a function you
don't understand, provided you "trust the author" -- but
since the author is unnamed, we do not have the means to
tell whether he is trustworthy.
They are function-like macros. Unfortunately some of the arguments are evaluated twice - a sng with the C macro system. I find lower case more tasteful than upper
The book next offers two macros (mentioning two more,
but not implementing them). The most obvious thing about
the book's macros is that their names consist entirely of
lower-case letters. While this is legal in C, it is far
more usual to name macros in upper-case -- some coding
standards, in fact, insist on this. The macros the book
offers aren't wrong, exactly, just in poor taste.
x = clamp(x, 0, 255);
is far easier on the eye than
x = CLAMP(x, 0, 255);
The upper case gives the macro an emphasis it shouldn't have.
Cut and paste is generally a far superior method. Libraries are fine if you are implemeting something fundamental like OpenGL, but not when you need a list of dependencies in your code. No one wants to link in five libraries all with conflicting definition of "bool" just to use a few string functions.
The chapter closes with an argument that putting code
in libraries that can be shared by many programs is a Bad
Thing; the "right" way to re-use code is to paste a copy
wherever you happen to need one. (No, I am not making this
up!) And just for laughs, the chapter ends with an English
error.
Need to check those bugs.
Statistical summary of "Some Simple Functions:"
- Number of function implementations shown: ten
- Number of functions that require compile-time
diagnostics: five
- Number of functions with bugs (beyond required
diagnostics) spotted by this reader: four
Thanks for the input.
- Number of functions with bugs known to the author
(but published anyhow): one
- Number of macro implementations shown: two
- Number of bad macro implementations shown: two
- Influence of this more extensive reading on the
reader's opinion of the book: negative
--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm
.
- Follow-Ups:
- Re: Malcolm's new book - Chapter 1 review
- From: Old Wolf
- Re: Malcolm's new book - Chapter 1 review
- From: Kelsey Bjarnason
- Re: Malcolm's new book - Chapter 1 review
- From: Richard
- Re: Malcolm's new book - Chapter 1 review
- From: Eric Sosman
- Re: Malcolm's new book - Chapter 1 review
- From: Ian Collins
- Re: Malcolm's new book - Chapter 1 review
- From: pete
- Re: Malcolm's new book - Chapter 1 review
- References:
- Re: Malcolm's new book
- From: Kelsey Bjarnason
- Re: Malcolm's new book
- From: Malcolm McLean
- Re: Malcolm's new book
- From: Kelsey Bjarnason
- Re: Malcolm's new book
- From: Malcolm McLean
- Re: Malcolm's new book
- From: Kelsey Bjarnason
- Re: Malcolm's new book
- From: Richard Heathfield
- Re: Malcolm's new book
- From: Kelsey Bjarnason
- Re: Malcolm's new book
- From: Malcolm McLean
- Re: Malcolm's new book - Chapter 1 review
- From: Eric Sosman
- Re: Malcolm's new book
- Prev by Date: Re: Malcolm's new book - Chapter 1 review
- Next by Date: Re: Malcolm's new book - Chapter 1 review
- Previous by thread: Re: Malcolm's new book - Chapter 1 review
- Next by thread: Re: Malcolm's new book - Chapter 1 review
- Index(es):
Relevant Pages
|