Live data from Hacker News

Beginning to learn C: What resources should I be using?

news.ycombinator.com

1–6 of 6 posts

Beginning to learn C: What resources should I be using?

#1
Title may be misleading; I've already started.

First I was 10 years old (or so) and my father tried (with some success) to teach me to program in C. ~5 years later, and after learning Python, I've decided to give it another try. So I joined ##c on Freenode and was given the direction to go study K&R and avoid a specific set of other books (Learn C The Hard Way, Learn C in 21 Days).

So... I followed that advice. I've spent most of the last 2 days trying to absorb as much as I can about C, and what I've found is that while it feels like coming home in a way, there are some significant differences in the C I first learned to write and the C in K&R.

Examples:

I write 'int main()', K&R writes 'main()'

I write 'return 0;' at the end of the main loop, K&R does not.

I encapsulate everything (if, while, for, etc) with brackets, K&R often does not use brackets at all. I'm not sure why.

After noting this, I decided to find out why these differences were there. And apparently, K&R, the resource everyone told me to use to the exclusion of all others, is almost universally considered outdated. Though I know that C is an old language, I want to learn it as it's used in the present day.

What should I actually be learning from? And who should I trust? Honestly, I feel slightly betrayed.

Re: Beginning to learn C: What resources should I be using?

#2
you should feel betrayed!

people are often biased and unempathetic. you need to follow your gut. when lots of people are saying something illogical then you need to keep looking for more people before you decide on a course of action. this is an important life skill.

best of luck. i learned a lot from learn c the hard way and other internet resources. i have no interest in k&r other than the curious hold the royalty holders have on aging baby boomers.

Re: Beginning to learn C: What resources should I be using?

#3
C is a language that has come a long way since the original K&R. And quite frankly, K&R is a good source to get the feel of C, but it doesn't really reflect how C is used in practice today. That said, I've found "Modern C" by Jens Gustedt [1] to be very good at teaching the basics of the language up to the intermediate level.

At some point though, you need to study projects and other various tools in order to get a better understanding of how C is used and how to write more advanced C code. Things like valgrind, gdb, strace, etc become more and more important, and eventually you'll find that most of the techniques you use in other languages are just represented differently in C (such as OOP).

Good luck, and honestly, don't force yourself to learn it if you don't feel you need to. You're young enough that you'll learn it eventually if you really need it.

[1] http://icube-icps.unistra.fr/img_auth.php/d/db/ModernC.pdf

Re: Beginning to learn C: What resources should I be using?

#5

C is a language that has come a long way since the original K&R. And quite frankly, K&R is a good source to get the feel of C, but it doesn't really reflect how C is used in practice today. That said, I've found "Modern C" by Jens Gustedt [1] to be very good at teaching the basics of the language up to the intermediate level. At some point though, you need to study projects and other various tools in order to get a b…

Thanks for the link.

Re: Beginning to learn C: What resources should I be using?

#6
I too learnt C from K&R. It is good for coming to grips with the language. Coming from Python, you might have to come to grips with pointers, typedefs, structs, etc.

Once you have the basics sorted, the real learning comes from reading some open source project. There are lot of conventions and patterns in use. They are dictated by the compiler (and other tools) being used and the project's conventions.

Personally I learnt a great deal from studying Unix kernel sources from the John Lions books. A more modern equivalent is "Linux Core Kernel Commentary".

Once you read up on different open source projects, you will see that there is no one way of using C.