Live data from Hacker News

Ask HN: Learning C

news.ycombinator.com

1–10 of 66 posts

Ask HN: Learning C

#1
Throughout my career, I've viewed C as the sleeping monster that mere mortals such as myself dare not waken. However, as I increasingly seek to achieve more complex goals in my projects, I find myself encountering C libraries (such as GMime) which will answer all my questions, if I could actually program in C. I have a copy of C Primer Plus Fifth Edition at hand, a development FreeBSD server as well as my Mac, but would like to ask of this community if they are aware of any other references, such as old CS course materials, which may help. Many thanks in advance. I realise that this is a long term goal, but feel that with my taste in server platform and operations software, C will prove a boon to me.

Re: Ask HN: Learning C

#4
C isn't hard, don't worry! It's actually a fairly simple language. But it's medium/low-level and there is a lot of power within its simplicity. Fast to learn, but a long time to master, as one might say.

I don't know what people are using to learn C these days, but the standard has always been the white book http://www.amazon.com/Programming-Language-Prentice-Hall-Sof...

You will find yourself spending more time thinking about programming concepts rather than dealing with C syntax, since it's pretty concise. I don't know how difficult it is to learn about pointers if you have already been programming for a while but haven't had to use references directly, but it's very important to learn. C does not do too much for you on its own, so handling references yourself is an important skill. It will also help you understand how higher level languages and concepts work.

If you are working through it and find that you're enjoying yourself, congratulations, you're a programmer :] Then it's time to pick up the 1st volume of Knuth and start working through that.

Re: Ask HN: Learning C

#5
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 and a regular function call, and it doesn't take much time to learn.

Books by W. Richard Stevens were old when I was learning, and older now, but they were the best guides to taking it to the next levels. You can pick up a lot of tricks and stylistic pointers from him while learning about UNIX features and networking. Maybe somebody will chime in with a more up-to-date resource that does the same thing.

Re: Ask HN: Learning C

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

Re: Ask HN: Learning C

#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 Java, or even C++), and you're most of the way there.

In addition to K&R, I've hears that Steele and Harbison's "C: A Reference Manual" is very good, although I haven't read it personally.

Re: Ask HN: Learning C

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

Re: Ask HN: Learning C

#9
post #4

C isn't hard, don't worry! It's actually a fairly simple language. But it's medium/low-level and there is a lot of power within its simplicity. Fast to learn, but a long time to master, as one might say. I don't know what people are using to learn C these days, but the standard has always been the white book http://www.amazon.com/Programming-Language-Prentice-Hall-Sof... You will find yourself spending more time thin…

Indeed, the problem with C is just that. Once you understand how it works, you'll realize it's just a thin abstraction layer over assembly language. It really is just that simple. My last job was almost purely C, and what made C "scary" at times were:

1. naming conventions. I don't know why C programmers use the strange names that they do.

2. macros. C macros are a pain to read and follow.

I hope things will be easier to learn if you know this going in, because that's really all there is to it.

The catch with C is that while it is simple, writing good code with it is not. You have two tools for metaprogramming: macros and function pointers. C++ classes seem evil, until you see what people do in C in the absense of any mechanism for polymorphism.

Thankfully for you, you probably will only ever need to deal with libraries, not applications, so you'll never have to deal with the hell that comes with trying to use C for higher level work.

Re: Ask HN: Learning C

#10

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

It's not even a very good way to learn C. The idioms and best-practices for C programming have evolved substantially, even since the second edition was published, and some of the code samples look a bit dated.

As the parent said, you'll appreciate C only if you learn about machine architecture and Unix. Diving into a large codebase will get you acquainted with "modern" C.

I've found the book C Traps and Pitfalls to be the book to get you to think like a C programmer. The C Puzzle Book is pretty good for exercises, and Expert C Programming does a good job exposing the ugly side of C.

Post reply on HN