Live data from Hacker News

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

news.ycombinator.com

51–60 of 70 posts

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

#51

I'd say that K&R C is a historical relic and not the best way to learn the language anymore. I have the ANSI second edition. It's way outdated. If you have some programming language experience already I'd suggest going with 21st Century C by Ben Klemens. There's a decent refresher on the language in the appendix and most of the book spends time talking about all of the things most text books skip over: tooling, debug…

I will second Expert C Programming.

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

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

I didn't know of the critique of K&R in LCTHW that got taken down. I'm surprised that the rabble-rousers weren't able to take it in context. When K&R was first authored, there were no "seasoned" C programmers from which to draw on for their experience in writing safe, secure C code!

Yes and no. Perhaps when the first edition was published that was true, but the second edition was published 11 years later.

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

#53
post #40

A small detail that has been missed by most responses to the question is OP isn't asking how to learn how to write the best possible 2015 C code for 2015 C tasks, but asked for reverse engineering previously written code (perhaps written VERY long ago). Depending on the age and quality of the code OP is reverse engineering, learning a very modern style of coding might somewhat oppose OPs goal. I'd advise OP to rephra…

hmm, I think my question is fine how it is. I want to learn C, I am asking HN their opinion of a book I am thinking about. If you want specifics, I would revise my question to something like "I really want to learn how to reverse engineer malware so I'm starting this goal by learning C, is K&R a good resource to learn C from?"

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

#54
post #26

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.

"I ask honestly, why?" As you say yourself, it is part of your history, you've probably forgotten which concepts that K&R taught you and the OP is trying to learn C from scratch. The OP mentions that they are learning C to help them with their reverse engineering skills, so learning about the older ways that C was programmed is also invaluable as those insecure programming techniques are still (unfortunately) widely…

"the OP is trying to learn C from scratch"

This weighed heaviest in my mind. K&R is a poor book to learn modern C. Its like saying a person starting out with Fortran today should learn from a book written for FORTRAN 77. It might be ok later once better habits have set in, but for someone who didn't live through that era, it just seems like a waste of time and money for learning modern C.

I am still convinced its a signal to others and an aspiration for what we want out of language authors, but it just isn't up to date for the task of being the first C book someone reads.

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

#56
A much more complete book than K&R is "C: A Reference Manual", which has much better explanations.

See it here: http://careferencemanual.com/, at its home page.

Or at Amazon here: http://www.amazon.com/Reference-Manual-5th-Edition/dp/013089....

Turn to this book when you have questions. The authors are Harbison and Steele. If you become a C programmer, you will want and need this book. So you may as well get a copy now.

Another (more advanced) book is The C Puzzle Book.

http://www.amazon.com/The-Puzzle-Book-Alan-Feuer/dp/02016046....

It's older and I'm not sure it's totally up-to-date with the latest version of C. But it's still very valuable. If you finish this book, you will be a C ninja, and it isn't too hard.

K&R is outdated, in my opinion, because it is too skimpy.

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

#57

Earlier quoted context omitted.

I didn't know of the critique of K&R in LCTHW that got taken down. I'm surprised that the rabble-rousers weren't able to take it in context. When K&R was first authored, there were no "seasoned" C programmers from which to draw on for their experience in writing safe, secure C code!

Yes and no. Perhaps when the first edition was published that was true, but the second edition was published 11 years later.

When the second edition was published in 1988, there were seasoned C programmers, but security wasn't nearly the issue it is today. Since there was no World Wide Web yet, most computer systems weren't exposed to a global network full of people who wanted to crack code for profit. There was no e-commerce, no on-line banking, etc.

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

#58

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.

Actually, that's why I happily offer to help those who are interested in learning C to come and ping me with code snippets and to even assign them exercises and walk through them step by step with people. The world needs more competent C programmers, and if I can help with that at all, I'd like to :)

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

#59
post #46

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 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.

It is shocking to me that someone who doesn't even use C is handing out critiques of any book focused on C.

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

#60

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.

If you have any questions about that approach, feel free to email me.
Post reply on HN