Re:Learn C Programming with Open-Source Books
by sigjuice on Monday February 06, 2017 @10:46AM
(#13580469)
Is there a list of this very nasty 1970s styles of coding somewhere? Is it mainly that it is outdated and doesn't describe the lastest C standards?
[ Parent
| on HN ]
Re:Learn C Programming with Open-Source Books
by bluetomcat on Monday February 06, 2017 @11:08AM
(#13580738)
It is bad not only because it predates C99, but also because virtually any example consists of a couple of global variables/fixed-size arrays, a couple of badly named functions which operate on the globals and use some very "descriptive" names of the local variables. This book was born in an era when the modern understanding of "good code" was barely honored at all.
Re:Learn C Programming with Open-Source Books
by gtz62 on Monday February 06, 2017 @12:08PM
(#13581512)
"Relying too heavily on external variables is fraught with peril since it leads to programs whose data connections are not at all obvious" - k&r, ch. 1
Who are these Kernighan and Ritchie guys? They obviously just don't understand "good code", terrible book!
Re:Learn C Programming with Open-Source Books
by syntheticnature on Monday February 06, 2017 @12:21PM
(#13581660)
People pick up on what you do, including supplied examples, not what you say.
(And I say this as someone who likes K&R.)
Re:Learn C Programming with Open-Source Books
by bluetomcat on Monday February 06, 2017 @12:28PM
(#13581741)
Take, for example, the declaration parsing example and honestly tell me that this isn't crappy code by any modern standard:
enum { NAME, PARENS, BRACKETS };
void dcl(void);
void dirdcl(void);
int gettoken(void);
int tokentype;
char token[MAXTOKEN];
char name[MAXTOKEN];
char datatype[MAXTOKEN]; /* data type = char, int, etc. */
char out[1000];
main() /* convert declaration to words */
{
while (gettoken() != EOF) { /* 1st token on line */
strcpy(datatype, token); /* is the datatype */
out[0] = '\0';
dcl(); /* parse rest of line */
if (tokentype != '\n')
printf("syntax error\n");
printf("%s: %s %s\n", name, out, datatype);
}
return 0;
}
Re:Learn C Programming with Open-Source Books
by eltoozero on Monday February 06, 2017 @02:09PM
(#13582807)
Pg 124 from 2nd edition where this code is pulled (emphasis mine):
"[T]he programs are intended to be illustrative, not bullet-proof, there are significant restrictions on dcl."
In context this code illustrates the points they're trying to convey about complicated declarations quite well and is a precursor to understanding typedef later in the book.
Also, you left the nice inline comments off the variable declaration block.
Re:Learn C Programming with Open-Source Books
by ejanus on Wednesday February 08, 2017 @04:35AM
(#13597024)
I would like to see where typedef could have been used?
Re:Learn C Programming with Open-Source Books
by Koshkin on Monday February 06, 2017 @01:10PM
(#13582222)
"Modern standard" or not, I find this piece of code highly readable, and, in general, very good for what it does, at the level (of simplicity, perhaps even "primitivism") at which it was intended to do that.
Re:Learn C Programming with Open-Source Books
by berkus on Monday February 06, 2017 @01:57PM
(#13582709)
This piece of code is crap - it's not functional, keeps implicit state.