Live data from Hacker News

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

news.ycombinator.com

11–20 of 70 posts

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

#11
If you're serious about reverse engineering, you might consider learning assembly language and C side-by-side. Learn an assembly language (with the Art of Assembly Language Programming or similar) while working through K&R (or another introduction to C), but compiling everything with gcc -S and reading the assembly output (initially, compile with -O0; optimization will obscure the output too much). This would be slow going, but you'd really solidify the connection between the low-level and the higher level, which is presumably what you are really looking for when you say you want to learn C. (A lot of things you're going to reverse engineer will have to be reverse engineered at the assembly level, not the C level.)

K&R would be fine for this purpose, I think. As a more general introduction to C, I think it's still great, but really needs to be paired with something more modern if you're planning to actually develop applications in C.

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

#12
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…

I might look into the K N King book, looks like another hn user is recommending it as well.

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

#13
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 critique of ZedShaw's book appears to be

> Too many factual problems and a presentation that gets you to do things wrongly before being shown how to do it correctly, and not even always then.

Eh?? Isn't that the whole point of "Learn __ the Hard Way"? ie., by making mistakes and learning from them?

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

#14

If you're serious about reverse engineering, you might consider learning assembly language and C side-by-side. Learn an assembly language (with the Art of Assembly Language Programming or similar) while working through K&R (or another introduction to C), but compiling everything with gcc -S and reading the assembly output (initially, compile with -O0; optimization will obscure the output too much). This would be slow…

What you described is exactly how I want to learn C: together with ASM but wasn't sure how to go about it. But know you have gave me a general idea on how to go about it, thanks.

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

#15
I think it is hard to find a more well-written and concise introduction to a programming language than K&R.

That being said, the example code in the book is sometimes terse at the expense of readability (and security). I would try to pick up a more modern, and defensive, coding style from the web.

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

#16
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,…

Then maybe it would be a good idea to go ahead and read K&R and then afterwards read Zed's book?

K&R is a seminal work. I think it should at least be read because every C programmer has read it -- and so you are on common ground. Also, it is a better reference (has the grammar, precedence tables, etc.)

To learn C -- I'd recommend LCTHW.

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

#17
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 text book will never make you good at C programming; like many other languages (or perhaps programming in-general with the exclusion of highly-academic languages), creating your own personal projects and learning as you go with a mentor to guide you is probably the single best way to become proficient.

Second, eventually, you should read the current Spec (or at least, the latest draft and all its TC). Before getting to that, if you are convinced that a text book would be helpful, go look at http://icube-icps.unistra.fr/img_auth.php/d/db/ModernC.pdf

All the best,

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

#18
K&R (draft ANSI edition) was my first C book and still sits on my shelf. I learned C code from it and it was my goto reference for many years. There is a fair bit of nostalgia for that book.

But, at this point in my life, I believe the K&R book is a good read if you are into the history of programming languages or going to write a book about your own language and want to avoid the bloat common in computer books. It is not a great modern C book and has not been updated in years. I wish this wasn't true, but pointing new programmers to that book in anything other than a historical context is just not serving them well.

It is really too outdated and does not cover the language as it is used or safe programming in the language. I'm not sure what the replacement is these days.

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

#19
post #13

Earlier quoted context omitted.

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 critique of ZedShaw's book appears to be > Too many factual problems and a presentation that gets you to do things wrongly before being shown how to do it correctly, and not even always then. Eh?? Isn't that the whole point of "Learn __ the Hard Way"? ie., by making mistakes and learning from them?

Also, K&R does many things the wrong way for expediency. It's fine if you know that already, but newbies do not know that.

The main critique of Zed seems to be that he didn't say it was impossible to protect a C function from the caller. So what? There is a big difference between his suggested style and the style you'd get from an uncritical reading of K&R, even though neither is 100% safe from the caller.

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

#20
You should definitely have a copy of K&R on your desk.

A book I read alongside K&R was "Illustrating C" by Donald G. Alcock, even though it is out of print and quite hard to find I'd recommend hunting a copy down as it explains the concepts visually and for me, it was the only book that made things fall into place.

http://www.amazon.com/Illustrating-C-Ansi-Iso-Version/dp/052...

Post reply on HN