8 ms·
Since learning Rust I wanted to learn some C to be better able to consume pure C libs or embed Rust into C apps. Along Modern C I found these modern(ish) C boo
by esamatti 6y ago
Since learning Rust I wanted to learn some C to be better able to consume pure C libs or embed Rust into C apps.
Along Modern C I found these modern(ish) C books:
- C Programming: A Modern Approach, 2nd Edition by King
- 21st Century C by Ben Kelemens
- Learn C the Hard Way by Zed Shaw
Can anyone recommend some of these for my background?
Besides Rust I've mostly used Webdev languages JS (mostly TypeScript these days), Python, Ruby, PHP, some Java back in the day.
- Areading314 6y agoThe best C book is the Kernighan + Ritchie book "The C programming language", hands down. This is also one of the best books on practical computer science available today. Other books could help to provide a more modern take on how to adapt the language to 2020, but the original K+R book is still the best way to really learn the language.
- nine_k 6y agoDo people still use the K&R style of declarations? OTOH a microcontroller is an acceptable approximation of a PDP-11, so much of the old approaches are very directly applicable.
- sureshv 6y agoThe 2nd edition circa 1988 uses ANSI style declarations.
- pjmlp 6y agoAnd has never been updated ever since. Latest standard revision is ISO C17.
- Koshkin 6y agoThank god. I’d hate to see the book grow to a thousand pages.
- pjmlp 6y agoOn the other side it is full with outdated information and examples that lead to unsafe C code, not much to be happy about.
- saagarjha 6y agoName one from the second edition? I found the book’s examples to be fairly timeless.
- pjmlp 6y agoIt is 2000 km away from where I live. Not going to buy another copy just to make someone happy on Internet. But still, most examples don't proper error correction, don't teach about use of bound checked strings and vectors, and if I remember correctly there are examples with gets().
- saagarjha 6y agoI hear there are PDFs floating around on the internet, not that I would know anything about this of course ;) My copy has no examples that use gets, although it is mentioned and I would agree that any such mention without a disclaimer that the function is impossible to use safely is a defect. Error handling, however, is generally present (or left out for brevity and noted). The functions in the standard for dealing with bounds checks are a new addition to the standard and a pox on the language regardless so it's not the best example of something new that the book should cover.
- pjmlp 6y agoFor those that care about security in C, even those functions are not the way to go, rather something like https://github.com/antirez/sds https://github.com/antirez/sds. This is something that the book fails to teach, as it also has no mentions of modern static analysers practices, naturally given the book's age. So at the end we get yet another C newbie writing future CVEs.
- Koshkin 6y agoI am sensing a confusion. Syntax has nothing to do with applicability to microcontrollers.
- nine_k 6y agoYes. But the general approach does. If you drop down to C on x64, you likely deeply care about cache efficiency, pipelines not stalling, etc.
- pjmlp 6y agoOnly for historical reasons, it is full of examples of bad practices regarding safe C code by modern standards.
- Koshkin 6y agoBut C is “bad practice” (by design, and I mean it in a good sense).
- pjmlp 6y agoIdeally C should be avoided as much as possible outside kernel code. However it has gotten so deep into IT infrastructure, thanks to the hegemony of UNIX/POSIX clones, that even if starting today no more greenfield software would be written in C, and its copy-paste compatible languages, Objective-C and C++, it would take generations to clean it up and it would never be 100% replaced, as proven by mainframe environments and their languages. So for the use cases where C isn't going away no matter what, we should strive for newer generations to improve their code quality and not to repeat bad practices from the past.
- satysin 6y agoI've been programming in C for twenty years now and K&R has a special place in my heart however I do not think it is the best book for a beginner to learn C. If you're coming from COBOL and wanting to learn C (like the target audience at the time the book was written) ok perhaps it is a good book for you. But if you're coming from something like Python or Java or JavaScript (or even no language at all) there are better options such as K N King's A Modern Approach. K&R is a fantastic book in its own right and I certainly think once you feel more comfortable with C it is a superb book to read and more importantly complete as many of the exercises as you can. It is that I have seen too many people come from higher level languages or with no programming knowledge and find K&R frustrating due to its assumption the reader is already a programmer in some other (1970s) language with a fundamental understanding of some programming concepts.
- bluetomcat 6y agoK&R is a worthy historical artifact on its own, documenting the then prevailing programming styles and problems of interest, and the overall cultural vibe of the programming community back then. It just takes you back to the creative and somewhat unorderly 1970s atmosphere in Bell labs, with its former hippies now wearing big glasses and colourful sweaters.
- runbsd 6y agoWorking at Bell Labs in the 70s/80s must have been interesting.
- runbsd 6y agoThanks, this is really useful info for someone who wants to learn C coming from Pyhon, etc.
- saagarjha 6y agoI think it’s a great book to read first; it is concise and correct and gives a very good idea of what C is about. However, I would immediately follow it up with the newer parts of C, going more into the modern definition of undefined behavior, practices to keep your code correct in larger applications, how to debug issues, etc.
- GeertVL 6y agoThe best book for me was the King book. Clear. Thorough. And most importantly the order of the chapter topics. And definitely do the projects to practice.
- wsc981 6y agoI haven’t read any other books from that list but the King book, but I found it very well written and easy to understand as well.
- pjmlp 6y agoI would add to that list, "Secure Coding in C and C++, Second Edition" https://www.oreilly.com/library/view/secure-coding-in/9780132981989/ https://www.oreilly.com/library/view/secure-coding-in/978013... "Extreme C" https://www.packtpub.com/product/extreme-c/9781789343625 https://www.packtpub.com/product/extreme-c/9781789343625
- dave84 6y agoI was pleasantly surprised by Extreme C.
- liendolucas 6y agoExpert C Programming (Deep C Secrets) by Peter Van Der Linden is a fantastic book.
- macintux 6y agoSeconded. Easily my favorite programming book for any language.
- dasb 6y agoKing's book is really good.