Live data from Hacker News

Ask HN: Should I use K&R to learn C?

news.ycombinator.com

41–50 of 70 posts

Re: Ask HN: Should I use K&R to learn C?

#41
You are not going to learn C with one book. K&R is one you should know, but it is not everything you will need.

I think it still is a nice book for beginners, but not the most pragmatic option. You may prefer to start with something more up to date. But if you really want to learn C, read it at some point.

As a side note, even if C was already a dead language, I would still recommend to read the book just as an example of good writing.

Re: Ask HN: Should I use K&R to learn C?

#42
There's a lot of great book recommendations in this thread already, so I will just add that learning C so that you can reverse engineer anything more than trivial programs is kind of like memorizing a parts manual so you can reverse engineer your car.

Yeah you'll be able to identify all the parts and in theory what they do, but you won't understand the why of things. There's really no substitute for experience in understanding why something is designed the way it is.

Re: Ask HN: Should I use K&R to learn C?

#43
I wouldn't recommend K & R to a beginner. To a first approximation C is portable assembly language and Kernigan and Ritchie wrote for an audience approximating their coworkers at Bell Labs - people with experience in Assembly language.

A book I would recommend, particularly if Zed Shaw's Learn the Hard Way does not appeal to you is Head First C.[1] The underlying pedagogy of programmed instruction is similar. The exercises are more diverse, the tone is lighter, and the overall presentation more approachable.

Good luck.

[1]: http://shop.oreilly.com/product/0636920015482.do

Re: Ask HN: Should I use K&R to learn C?

#44
For reverse engineering? You should use every single thing you can get your hands on that helps you learn. The K and R are the two people who wrote C. Of course you should read their if you want to learn C. Then read, and WRITE the code in, everything else you can get your hands on to learn a programming language. It may only take one book, it may take 10, but that's how you do it.

Then after that go learn Assembler, or even better, implement a compiler. You'd probably learn a ton of the things you need to know for reverse engineering code from just making one simple compiler.

Re: Ask HN: Should I use K&R to learn C?

#45

Personally, I have found most C books to be colossal failures. K&R is a great text that would be good for you to read eventually (if only to see how far C has come), but to learn how to do modern programming, K&R probably is not where you should go. Additionally, LCTHW let me down significantly (regardless of what you think of the author). If I could make two recommendations to you, the first would be that reading a…

> with a mentor to guide you

I wholeheartedly agree. Not to say they're mutually exclusive, but nothing comes close in terms of education / time density to an experienced programmer telling you what you did wrong and why.

Re: Ask HN: Should I use K&R to learn C?

#46
post #4

There was a very good critique of K&R in Learn C the Hard Way that got taken down because of (IMO) undue backlash. The gist of it was that K&R ignores the safety problems in C and there is no discussion of the habits/constructs seasoned C programmers have developed to make sure their code is safe. Of course, many of those habits were developed after K&R, but that's why we need revisions and new sources. In its place,…

Interesting, last time I asked on various C boards about learning resources, Zed's book got ripped apart. http://www.iso-9899.info/wiki/Books

The man who moved my book into the "avoided" category admitted to me in an email that he did it just because of my K&R critique, not because of the book's quality, is not a C programmer, hasn't coded C professionally ever, and works doing PHP with almost no C experience.

Re: Ask HN: Should I use K&R to learn C?

#48

Earlier quoted context omitted.

"You should definitely have a copy of K&R on your desk." I ask honestly, why? Other than nostalgia and as a signal to others what does it bring the modern C programmer? I have it on my shelf, but it is part of my history.

When I read it first time, it was ok to start to write C programs. When a read it again later I understood that it was much deeper and complete than it seemed first time. Then, every time I learned something in programming using C (studying operating systems), I read K&R again and found that the answer was there even if I didn't see it before. So it was a good way for me to "validate" that I understood something new.…

It's still a historical relic with little to no applicability today. K&R style C is awful by comparison with modern C.

If you want to learn C history, it's invaluable. If you want to learn C, it's only the first of many books you'll have to read.

Re: Ask HN: Should I use K&R to learn C?

#49
post #27
post #8

K&R is a great book however I feel there are better books these days. My two personal recommendations are C Programming A Modern Approach by K N King (2nd edition) and Programming in C by Kochan. However the exercises in K&R are excellent so make sure you do them all. Actually the cost of K&R is justified just for the exercises IMHO. Also get Understanding and Using C Pointers by Richard Reese, it is a must have. Two…

Seconding Understanding and Using C Pointers by Richard Reese and 21st Century C, but more for after you've gone through a more basic resource. I haven't looked at Kim King's book, but if it's anywhere near as good as his intro to Modula-2, it will be excellent to learn C from.

Yeah 21CC and U&UCP are for once you are comfortable with the language not for beginners. U&UCP will be a book to keep by for many years as well as it is pretty much the gospel for pointers IMHO.

Re: Ask HN: Should I use K&R to learn C?

#50
Yes, I would highly recommend reading it, with the exception of Chapter 8.

Some of the other people have said things like: "The gist of it was that K&R ignores the safety problems in C and there is no discussion of the habits/constructs seasoned C programmers have developed to make sure their code is safe. Of course, many of those habits were developed after K&R, but that's why we need revisions and new sources."

This is indeed extremely important, but I also think in an introductory book these details will be very overwhelming. Safety in C is a very complicated topic, and indeed entire books have been written about it[1].

I find these "critiques" rather misguided. After all, we all know Newton's laws are an inaccurate picture of reality, but one would hardly start teaching quantum physics straightaway. C is a hard language with a lot of bizarre edge cases, and K&R C does an excellent job of presenting the language without all these pesky details.

The second criticism seems to be that it is outdated. This is true, but you can catch up with coding conventions and best practices very quickly.

To summarize, K&R C is excellent for introducing people to C. I would suggest completely ignoring safety issues et cetera at the start and just have fun solving the exercises!

---

[1] Secure Coding in C and C++ is a really good book on this topic. http://www.amazon.com/Secure-Coding-Robert-C-Seacord/dp/0321...

PS: Since you are interested in reverse engineering, after finishing K&R C I would recommend reading Computer Systems: A Programmer's Perspective.

Post reply on HN