Live data from Hacker News

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

news.ycombinator.com

31–40 of 70 posts

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

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

If your goal in learning C is to write largish systems in it, then yes, "Learning C The Hard Way" is a good option. But the poster has said that s/he wants to learn for the purpose of reverse engineering. From this point of view, the main interest of C is just learning enough syntax to be able create functions and structs, and then compile them with gcc -S, so that you can see the assembly language that is generated…

Well if you want to start reverse engineering, I'd think you'd need a very deep understanding of C.

When reversing it doesn't help you if you know what a single instruction is doing. You need to be able to recompile the program in your head, and translate it back to high-level logic. You need far more knowledge of C than just the 'learn C in 21 days' stuff if you really want to start reverse engineering.

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

#32
I started with K&R as a college senior, 31 years ago. I found it tough going, but rewarding. It's a good book, but as others have said, you don't want to miss out on things that have been learned about C since it was written, including safety issues.

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

#33
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, debugging, the environment, useful libraries, etc. It also covers C99/C11 which is where anyone new to C should be starting these days, IMO.

You might also want to pick up Expert C Programming by Peter Van Der Linden. It's also starting to show its age but is useful for a deep, historical dive into why and how C evolved the way it has. It will keep you from yelling, "why on Earth would you ever do it that way!?" when you get a little frustrated with C's quirks. There are reasons most of the time (even if they're not always good ones in retrospect).

Also there's nothing quite like ordering yourself a copy of the specification. It's not insurmountable and easy to chew through a section here and there as you go along.

Happy hacking!

UPDATE: You can wait to purchase a copy of the ISO ANSI C specification as it can be quite expensive... you'll find it on http://webstore.ansi.org/RecordDetail.aspx?sku=ISO%2fIEC+989...

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

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

There was a very good critique of "earn C the Hard Way": http://hentenaar.com/dont-learn-c-the-wrong-way

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

#36
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 second the Programming in C by Kochan. I initially learned using the KNR but starting using this book after doing CS50 which is actually another great way to get introduced to C if you have the time to watch the lectures because they give you some training wheels that allow you to taste "doing things" with C before you know everything. There is something to be said for having that feeling of doing something cool once to motivate you to learn and get that feeling again.

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

#37
35 years ago, when I was told my 2nd freshman course in programming would be in Pascal, I bought the _Pascal User's Manual and Report_, read through it in one sitting, managed to remember most of it (Pascal is a small language) and was able to program in it - at a beginner level, of course. K&R is roughly the C equivalent. If you want the language and nothing but, then it should do you nicely.

My personal favorite, because it explains better (so I think) and dives into a little more depth where K&R leaves you to extrapolate on your own, is Peter van der Linden's "Expert C Programming" (Deep C Secrets): http://www.amazon.com/Expert-Programming-Peter-van-Linden/dp... . Also, I enjoy the author's entertaining style, and think it aids learning.

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

#38
post #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...

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

Note that I never used C at a very high level, and I don't know what is modern C programming, so it may not apply.

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

#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 rephrase the question to something like "I really want to learn how unixv6 works as a retro computing hobby project and I want to know what books the authors of unixv6 originally read to learn C". Or "I want to eventually be able to reverse engineer stereotypical 90s/00s microcontroller code so I want to know what textbooks an average EE used to learn C in that era"

Post reply on HN