News for hackers. Stuff that matters.
Re:Deconstructing "K&R C" by mechanical_fish on Tuesday January 10, 2012 @06:39PM (#3449677)
This chapter is explicitly teaching people what the author's idea of bad C code is: It has them read some, then tells them specifically what the gotchas are, then asks them to code up test cases for the flaws and run them through Valgrind.

Where's the "avoiding" here?

And which of the skills being exercised - imagining what kinds of bad things could happen, writing executable test cases, detecting segfaults - are not useful in the real world?

Re:Deconstructing "K&R C" by zedshaw on Wednesday January 11, 2012 @12:08AM (#3450530)
That's basically the point of this chapter. It's getting people to think like a hacker and try to break the code in unintended ways. That makes them better programmers and helps when avoiding common mistakes in C code.

Using K&R to do this is to give people a set of known good C code samples and show how even those can be broken and misused.

Re:Deconstructing "K&R C" by ori_b on Wednesday January 11, 2012 @12:47AM (#3450613)
Noble goal, but the way the chapter is written doesn't really come across that way, in my opinion.
Re:Deconstructing "K&R C" by aptwebapps on Wednesday January 11, 2012 @01:25AM (#3450682)
Speaking as someone who doesn't know C, hasn't read K&R, but who (usually!) has decent reading comprehension, it _does_ come across this way.

He's completely explicit about what he's doing and why. I don't understand how people can read that and still feel that he's being unfair.

Maybe I'm just too literal-minded.

Re:Deconstructing "K&R C" by ori_b on Wednesday January 11, 2012 @02:48PM (#3453320)
Calling string manipulation functions buggy and broken because they fail when you don't pass them a string is both wrong and silly.
Re:Deconstructing "K&R C" by bonzoesc on Wednesday January 11, 2012 @03:39PM (#3453570)
How do you test that something in C is a string?
Re:Deconstructing "K&R C" by tedunangst on Wednesday January 11, 2012 @04:26PM (#3453772)
You don't, because you can't. That's basically the same as the beginner question, "How can you test if a pointer has been freed?"
Re:Deconstructing "K&R C" by bonzoesc on Wednesday January 11, 2012 @05:20PM (#3453970)
It was a rhetorical question. What's the sense in having functions that operate on "strings" if you can't figure out what a "string" is at runtime? It's much saner to have functions operate on "strings that are 80 characters or less" or "a structure containing a integer `length` and an array of `length` chars."
Re:Deconstructing "K&R C" by ori_b on Wednesday January 11, 2012 @09:58PM (#3454847)
What's the sense in having functions that operate on "pointers to valid memory" if you can't figure out if it's "valid memory" at runtime?

The point is that the function is not buggy. You may not like the specification for it. You may think it should be designed differently. This is not the same as the code being buggy.

Re:Deconstructing "K&R C" by ori_b on Wednesday January 11, 2012 @09:54PM (#3454840)
The same way you test that a pointer is intialized to a valid value. You don't.
Re:Deconstructing "K&R C" by marshray on Tuesday January 10, 2012 @07:21PM (#3449829)
How about being able to work on a team of other programmers without insisting that everything ought to be done you own, completely unique, way?

If he truly had a better, more correct, way to write C code I would join him in trying to change the world. But the first example he gives is just factually wrong.

Re:Deconstructing "K&R C" by tedunangst on Tuesday January 10, 2012 @07:23PM (#3449838)
"we avoided classic style C strings in this book"

There's the avoiding. The skills being exercised are not a problem, it's the skill not being exercised that is a problem. You cannot be a competent C programmer without understanding strings and their relevant library functions.