Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Zed Shaw on Deconstructing K&R C

Name: Anonymous 2011-12-03 1:32

The book is still unfinished/alpha, but he's started work on this final chapter already.
http://c.learncodethehardway.org/book/learn-c-the-hard-waych55.html

When I was a kid I read this awesome book called "The C Programming Language" by the language's creators, Brian Kernighan and Dennis Ritchie. This book taught me and many people of my generation, and a generation before, how to write C code. You talk to anyone, whether they know C or not, and they'll say, "You can't beat "K&R C" . It's the best C book." It is an established piece of programmer lore that is not soon to die.

I myself believed that until I started writing this book. You see, "K&R C" is actually riddled with bugs and bad style. Its age is no excuse. These were bugs when they wrote the first printing, and the 42nd printing. I hadn't actually realized just how bad most of the code was in this book and recommended it to many people. After reading through it for just an hour I decided that it needs to be taken down from its pedestal and relegated to history rather than vaunted as state of the art.

I believe it is time to lay this book to rest, but I want to use it as an exercise for you in finding hacks, attacks, defects, and bugs by going through "K&R C" to break all the code. That's right, you are going to destroy this sacred cow for me, and you're going to have no problem doing it. When you are done doing this, you will have a finely honed eye for defect. You will also have an informed opinion of the book's actual quality, and will be able to make your own decisions on how to use the knowledge it contains.

In this chapter we will use all the knowledge you've gained from this book, and spend it reviewing the code in "K&R C" . What we will do is take many pieces of code from the book, find all the bugs in it, and write a unit test that exercises the bugs. We'll then run this test under Valgrind to get statistics and data, and then we'll fix the bugs with a redesign.

This will obviously be a long chapter so I'm going to only do a handful of these and then I'm going have you do the rest. I'll provide a guide that is each page, with the code on it, and hints to the bugs that it has. Your job is to then tear that piece of code apart and try to think like an attacker trying to break the code.

I think his approach is a Good Thing that the software world needs, but probably will dismiss anyway merely because of his curly brace style.

Name: Anonymous 2011-12-17 18:45

I haven't read either book. I will come forward and say that immediately. Having said that, the arguments espoused in this thread are refutable with just the fragments shown and some general background in programming.

Lots of kids are trying to be edgy here by flaming some guy who will never hear from them, showing empty bravado about how they are willing to live up to the consequences of their avoidable (programming) errors, or just acting as if they don't make them.

This a horse which has been beaten to dust, after countless reanimations. If you are using computational tools which don't assist you as a human, the least you can do is setup everything up yourself as to not burn your hair or somebody else's in the future.

By drilling into newbies's heads the idea that you should consider how you will fuck up tomorrow while trying to understand and use the programs you wrote today -in the end, to consider one's own human limitations, about the main reason to use computers in the first place- Zed Shaw is doing a huge favor to programmers of tomorrow and today.

Yes, it may be nitpicking of a great book, but considering how you idiots are foaming at the mouth because of that, it goes to show that it was necessary in the first place.

>>21
You should re-read a missive by Sussman to this board. It spoke of the perils of idolization of a revered figure, rather than soberly and rationally considering their contributions.

>>15
You so badass.

>>2,13
You speak as if strcpy's behavior in face of that edge case was a property of the Universe rather than some guy's design decision in spite of all its inconvenience.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List