3 ms·
"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
by gtz62 10y ago
"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!
- syntheticnature 10y agoPeople pick up on what you do, including supplied examples, not what you say. (And I say this as someone who likes K&R.)
- bluetomcat 10y agoTake, 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; }
- Koshkin 10y ago"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.
- eltoozero 10y agoPg 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.
- ejanus 10y agoI would like to see where typedef could have been used?
- ejanus 10y agoCould someone point out the craps in the code ? I only noticed excess use of global variables , and out array(can't figure out why it was index only at zero)