5 ms·
The proper way to learn C is to get a good book, read it, and do exercises along the way. Here’s an excellent book: C Programming: A Modern Approach, by King.
by krychu 7y ago
The proper way to learn C is to get a good book, read it, and do exercises along the way.
Here’s an excellent book: C Programming: A Modern Approach, by King.
Avoid online tutorials, and know that there are many poor books on C, including the recommended here “Learn C the Hard Way”. It has factual problems; see under “Stuff that should be avoided” here: http://iso-9899.info/wiki/Main_Page http://iso-9899.info/wiki/Main_Page
Note also, that unlike some other languages, C is not a language that you should learn by “trying things out”, due to the nature of “undefined behavior”.
Another recommendation would be to ask for CR on IRC.
Good luck!
- ianai 7y agoI’m always skeptical of telling people to not just try something out in programming. Yes, don’t just try to code up the next unix without knowing any c. But definitely getting your hands dirty isn’t going to instill any super bad mental/coding practices.
- geofft 7y agoC is a particularly weird language: it's entirely possible for things to work but - secretly introduce security vulnerabilities - stop working on a different compiler or after a compiler upgrade A generation of C programmers learned by trying things out, and they left us with superstitious beliefs about volatile (and also with imprisoned Uyghurs in China). We have the evidence and learning C by trial and error doesn't work. If you're going to write C (and there are definitely places where it's the right thing to use), learn it with more caution than you'd learn other languages.
- StrangeDoctor 7y agoOk I’ll bite, what on earth is the connection between Uyghurs and C?
- saagarjha 7y agoPresumably the fact that iOS had vulnerabilities that allowed for watering-hole style zero-day attacks on Uyghurs in China.
- ianai 7y agoBy that point you should be well beyond just messing around with c.
- geofft 7y agoShould be, yes, but again we have the evidence: the people whom Apple hires to write kernels regularly make these sort of mistakes. (Let alone the people that Microsoft hires, or the people who write various third-party Android drivers.) So whatever form of "should" that we have right now isn't working.
- geofft 7y agohttps://googleprojectzero.blogspot.com/2019/08/a-very-deep-dive-into-ios-exploit.html https://googleprojectzero.blogspot.com/2019/08/a-very-deep-d... This is one of the few places where writing C is objectively reasonable (an OS kernel) - and also one of the places where it's particularly dangerous if you get things wrong.
- acomjean 7y agoYou can learn by playing around, but its very helpful to have a guide in the begining. I had to start coding for work in C and without some good footing it was frustrating dealing with older code and creating new things with my very limited experience. (I had c++ which isn't the same.) Having spent a week going a book and getting up to speed helped greatly and increased my enjoyment, reduced my frustration fwiw.
- JustSomeNobody 7y ago> Note also, that unlike some other languages, C is not a language that you should learn by “trying things out”, due to the nature of “undefined behavior”. I disagree. You have to learn the ways in which things fail in any language you learn, especially a language like C.
- clarry 7y agoThe point is that you don't learn all the ways in which things fail in C by trying. At best, you learn the way in which they fail (or fail to fail!) on your specific platform/compiler/version/compiler options combo. If you want to know how things can fail (or, what things can fail in unspecified ways), you have to do a bit of reading and no amount of trying and experimenting will conjure that knowledge.
- zzzcpan 7y agoThere isn't a guide to learn how things fail on platform, compiler, version, options combo. Probably the only things that force you to systematically research and accumulate such knowledge is by writing a language VM in C or use C as an intermediate representation. Even writing a C compiler itself won't teach you that.
- clarry 7y ago> There isn't a guide to learn how things fail on platform, compiler, version, options combo. Yeah, that's the point. Chasing that knowledge is pointless. Instead, read the spec and find out what is legal and what is not. What is defined and what is not. Then you can stop worrying about how things fail and start worrying about not doing those things.
- ianai 7y agoTrying c out with a known solid testing framework seems like a much more practical and useful way to start. Telling people to read a text wall before doing any practice at any task is a great setup for failure. Math doesn’t do that. Physics doesn’t do that. Chemistry doesn’t do that. Literature doesn’t do that. Philosophy doesn’t do that. Etc. and of those philosophy is almost the study of text walls. But the best philosophy courses tend to start with a Socratic dialogue which is basically live action philosophizing.
- giomasce 7y agoSince UB can be a bad beast to tackle while learning C and C++, I would suggest to frequently compare what you learn with cppreference.com, and check that you understand that what you think matches what the standard dictates. Cppreference is not the standard, of course, but is sufficiently similar and much easier to read. If at some point you want to really become a master, then switch to the actual standard.