Live data from Hacker News

Ask HN: Learning C

news.ycombinator.com

21–30 of 66 posts

Re: Ask HN: Learning C

#21
post #6
post #3

Sure! Knowing C can definitely help with your overall understanding of how things work. It's especially helpful when learning new languages. I uploaded a copy of K&R ANSI C for you. In my opinion, it's probably the best way to learn it. http://whitepaperclip.com/files/ansi_c.pdf Have fun!

This book have copyright and you can buy it in libraries.

What makes you think he's not?

Re: Ask HN: Learning C

#22

Just about everybody who answers this will say that K&R is good, and I agree, but in addition to this I found that learning the basics of assembly was helpful. You can really see what's going on with the stack, what a pointer really is (pointers are really the only tough part about learning C, everything else will be the same old same old if you already know how to program), and the difference between a system call a…

I'd second this. In fact, Steve Yegge once said this about K&R ( http://steve.yegge.googlepages.com/ten-great-books ): This is an odd little book. It's frequently mistaken for an introductory programming book, which inevitably leads to frustration. It's not a good way to learn how to program; it expects that you're already familiar with machine architecture, assembly language, compilers, and at least one other high-l…

Agreed. I was scared of C for a long time, but it's actually a beautiful language. Deitel & Deitel's 'C; How to program' is a fine tutorial in both C and structured programming. YMMV.

Re: Ask HN: Learning C

#23
This falls more into the "tips and tricks" category, but I wish someone had mentioned this to me earlier. Once you have a good book on C[1] install all the man pages for the standard library. Once you start writing code, being able to say something like "man strlen" is amazingly useful.

I made the most progress in C when I took a class on OSs. Mainly, we wrote systems programming sorts of things like a simple shell, our own version of malloc, a simple user-space thread library, and so on. This really gave me insight into how these things would be done for real. Also, writing something really linked-list-heavy gets you a feel for pointers really quickly.

[1]: I have K&R ANSI C and I found it very concise and well-written. It is probably one step up from the "raw newbie" class of books in terms of difficulty, but should feel just right for someone already acquainted with (an) other language(s).

Re: Ask HN: Learning C

#24

Earlier quoted context omitted.

I'd second this. In fact, Steve Yegge once said this about K&R ( http://steve.yegge.googlepages.com/ten-great-books ): This is an odd little book. It's frequently mistaken for an introductory programming book, which inevitably leads to frustration. It's not a good way to learn how to program; it expects that you're already familiar with machine architecture, assembly language, compilers, and at least one other high-l…

C Traps and Pitfalls: http://www.literateprogramming.com/ctraps.pdf

If you enjoyed reading those 29 pages, you might find the entire book a decent read as well: http://www.amazon.com/C-Traps-Pitfalls-Andrew-Koenig/dp/0201...

Re: Ask HN: Learning C

#25
Best beginner text after K&R is Kelly and Pohl's "A Book on C"; very newbie friendly and at the same time uses traditional C examples (i.e. memory management, serializing and reading-back record-oriented data stored in structs, file and directory manipulation, string manipulation, etc.)

Most other C books will just treat it as a stepping stone for C++ which is a different beast, and a few awful offenders will stretch it to Java!

To see a few Algorithm implementations in C, there is no better friend than Robert Sedgwich's polyglot tome; it's the applied Knuth volumes that everyone keeps on their desk (quickly swapped for the actual Knuth volumes when expecting hacker guests.)

Along with C materials you will also need Unix materials. The two are inseparable and fuel each other. You already have a decent Unix in your Mac, and your FreeBSD is the best of the Unix breed bearing the original blood. For that there are no better companions than the books by Richard Stevens, both for system and network programming.

For larger scale software engineering you will need a few small to mid projects of your own. You will deal with header file and Make dependency problems, a few unix and processor portability problems and a few other stuff. The solution to those problems along with a fat library of useful routines are found in "C Interfaces and Implementations" by Hanson. It's a literate programming text where source code is interwoven with prose documentation and it's very self evident.

Along with productive C programming you might need to look into the darker side of C and Unix and follow the papers of the hacking underground (yes, HACKING, dispute the terminology all you want, but I think some blackhats deserve the noble noun more than javascript and CSS jockeys.) Unix and C have plenty of Not-TODOs to motivate plenty of caution. Hoglun and McGraw's Exploiting Software is the canonical C-Do-Not text books.

If you want to read library source code, your FreeBSD source code should give you plenty to keep you busy. Start with the sources for the games; I spent an enjoyable summer porting Minix games to DOS and taught me allot. There is also "The Standard Function Library", or SFL, google it, it has the cleanest C sources you ever seen. Highly recommended.

And should you ever want to write a C compiler, like I attempted, here is some advice: implement Oberon instead. Everything you could possibly learn at 1/100th of the headache.

Just the 2 cents of a guy who will only write C code again if there was a gun to his head ;-)

Re: Ask HN: Learning C

#27
post #8

A great resource I have enjoyed while brushing up my C skills has been CS107 at Stanford University on the web. http://www.stanford.edu/class/cs107/ You can find the lectures on academicearth.org, or on iTunesU if you prefer to download them that way. Jerry Cain is a great lecturer. I wish they'd post the assignments with the files they provide the students though. Maybe someday.

Yes. CS107 is the class that made C and assembly finally click for me. I have access to the assignment files; email me (in my profile) if you want them.

Re: Ask HN: Learning C

#28
Here is what worked for me.

Work through, in order, (1) K & R (2) C interfaces and Implementations by David Hanson (3) Deep C Secrets by Peter Van der Linden (4) Advanced Programming in the Unix environment

Good Luck!

Re: Ask HN: Learning C

#29
post #7

You should absolutely learn C. A good knowledge of C is a very valuable asset for all sorts of work, especially on Unix. Thankfully, C is straightforward to learn. The major concept you need to understand is pointers; once you've done that, there are some syntactic oddities to absorb (typedefs, function pointer syntax, arrays vs. pointers), and you should skim through the standard library (which is tiny compared to J…

I have Steele and Harbison's "C: A Reference Manual", and _is_ very good, but probably not for _learning_ C. It does have very good explanations of some under-the-hood things that I haven't found elsewhere. It is also a good reference on the C std library, and does a good job at pointing out possible incompatibilities between ISO C, `traditional' C, and vendor-specific dialects. One of the things that I have always found confusing about C is that code can be written in several ways, depending on how lax the compiler is about enforcing different versions of the C standard.

Re: Ask HN: Learning C

#30
post #8

A great resource I have enjoyed while brushing up my C skills has been CS107 at Stanford University on the web. http://www.stanford.edu/class/cs107/ You can find the lectures on academicearth.org, or on iTunesU if you prefer to download them that way. Jerry Cain is a great lecturer. I wish they'd post the assignments with the files they provide the students though. Maybe someday.

FYI, CS107 has changed considerably this year, so the course description on the current course site is a bit different from what you'll find on Academic Earth.

http://academicearth.org/courses/programming-paradigms

Post reply on HN