5 ms·
C is 38 years old. K&R V2 is 22 years old. What's the best modern C book?
- jmcguckin 16y agoK&R is a incredible book that every programmer should own. I honestly don't see why you would need any other book for C.
- gte910h 16y agoIt's style isn't correct for modern C is a good reason why.
- spacemanaki 16y agoDo you have any recommendations?
- gte910h 16y agoI'd go with http://www.amazon.com/Reference-Manual-Samuel-P-Harbison/dp/013089592X http://www.amazon.com/Reference-Manual-Samuel-P-Harbison/dp/... (non-aff link) for reference and something like one of these (non-aff links) for learning: http://www.amazon.com/C-Programming-Modern-Approach-2nd/dp/0393979504/ref=sr_1_3?s=books&ie=UTF8&qid=1289637913&sr=1-3 http://www.amazon.com/C-Programming-Modern-Approach-2nd/dp/0... http://www.amazon.com/Study-Guide-Programming-Modern-Approach/dp/0393969460/ref=pd_sim_b_3 http://www.amazon.com/Study-Guide-Programming-Modern-Approac... http://www.amazon.com/Programming-3rd-Stephen-G-Kochan/dp/0672326663/ref=pd_sim_b_2 http://www.amazon.com/Programming-3rd-Stephen-G-Kochan/dp/06... <=Dunno if it covers C99 either, but very basic
- tedunangst 16y agoIn general, categorizing someone's style preference as incorrect rarely leads to anything good. And in this instance, considering how many people still use and prefer the style in question, if you're learning C there's a good chance you'll be working with others on existing code using that particular style.
- gte910h 16y agoWhile you're correct, people dislike being confronted and its often easier to just not bother doing so, they are actually doing it incorrectly at this point if they're writing straight out of K&R 2nd ed. The style of the book is actually in error, as in, will cause compiler errors and subtle bugs in modern systems. They should know enough of what's gone on in the last 20 years of the C world to know K&R's second edition isn't the end all be all of C development. If you insist on writing to C90 (and for many applications, there are very good reasons to do so), you need to restrict yourself to the intersection of valid C90 and valid C99. You need to do this for the same reasons you would be writing C90 today (well, other than you never bothered to learn C99 in the last decade) K&R, 2nd Edition, does not observe this (as that's impossible for it to have done so, as it's so old). People who only read K&R, 2nd Ed, tend to not be cognizant of this most important of practices, which makes integration with their code and modern code a pain. In addition to failing to do this, it uses variable names from an era where terminals were 16x80. It uses increment operators in wholly inappropriate, precedence overeliant conditionals which would get you slapped silly the first time you cause a serious bug/heisenbug up in any C shop. It introduces the bad string functions (K&R is often pointed to people who never learned to not use scanf, etc) without any discussion of why you shouldn't ever think of touching them except in very small edge cases and toy programs, nor does it give examples of how to safely use them if you don't have any substitutes available. Past the actual deficiencies of the text, you still have other issues. At the end of K&R 2ndEd, You know nothing of dealing with characters and languages other than those that fit in ASCII, nothing of using modern threading/multiprocessing/parallelism, nothing of C99 (including why large variable span is bad), nothing of modern object oriented C (which has been in use since systems like X windows used it in the 80s), nothing of standard layouts of projects (or even C source files), nothing of safe string functions, nothing of the differences in variable sizes for different platforms, and in short, nothing of what's happened in 22 years worth of C betterment since this book came out. The 2nd edition of the book was published in 1998. You need more than that to get a handle on the core of C today. The end of 32bit ints and non ASCII languages alone mean the book needs more if you are going to use it. It's not enough on its own. If you find out a guy has learned C from nothing but it, it's a pretty reliable indicator "Nope, nope, no modern C experience" and you better make sure he's re trainable into accommodating how things are done today.
- Locke1689 16y agoNo. You should read K&R and then read the spec.
- deleted 16y ago[deleted]
- jonhendry 16y agoIt appears to be out of print. EDIT: Or maybe not. It's just surprisingly expensive (~$60) and Amazon apparently doesn't stock it themselves.
- xiongchiamiov 16y agoIt's expensive because people keep buying (and keeping) it.
- mncaudill 16y agoOne I really liked is _C Programming: A Modern Approach_ by K.N. King.
- noarchy 16y agoI personally learned C from that very book, and still own a well-worn copy of it.
- tptacek 16y agoI've been recommending CII for years: http://news.ycombinator.com/item?id=1245464 http://news.ycombinator.com/item?id=1245464 Past that, the trouble with C books is twofold: (a) do you really need that much book for such a small language? and (b) most of what you'd use C for (systems programming, codec design, bare-metal network programming, etc) is covered in domain-specific books that use... wait for it... C as their example language.
- jrockway 16y agoThe problem with books that use C as their example language is that they don't cover the finer points of C that are going to fuck you in real life. What happens when you strncpy a string that's the same length as n? How should fatal errors be handled? Who is responsible for memory allocation and deallocation? These are questions you need to know the answer to, but are unrelated to whatever the book is about. The best way to learn C is to learn some other programming language, and then apply the common sense you learned back to C.
- Locke1689 16y agoNo, you won't ever really learn that stuff until you just do it. Reading code is part of writing code so you should read some actual C code in your domain before ever writing code.
- alnayyir 16y agoWorking on it...
- brianwillis 16y agoReally? You're writing a C book?
- alnayyir 16y agoYessir http://hackerne.ws/item?id=1873413 http://hackerne.ws/item?id=1873413
- brianwillis 16y agoVery cool. My first reaction was that there wouldn't be much of a market for this, but after reading through the thread you linked to it's clear there is. Looking forward to seeing the final product.
- alnayyir 16y agoIt's not about market, although I'll be selling a physical copy. The digital will be free, as per Zed's example. I care deeply about programming, and about preventing software from turning into a mass cargo-cult profession. I want more systems-knowledgeable people out there who understand how things are and could be built.
- Jach 16y agoI always like Larry Ullman's books, especially his PHP and MySQL one. When I was learning C, his book was really helpful: http://www.larryullman.com/books/c-programming-visual-quickstart-guide/ http://www.larryullman.com/books/c-programming-visual-quicks... C as a language is pretty simple to learn. Using C in practice is where things can be tricky when you need to dance with the compiler and work on low level systems where a datasheet is always open, and if you haven't had your "Pointer Enlightenment" you're toast. Domain-specific books are key there and just continual practice.
- variety 16y agoK&R. It's like the C language itself: it just can't be improved upon. It was already meant for our time, when it was written.
- paradoja 16y agoWell, it doesn't cover the niceties of C99. While I own it, and it'd be the first C book i'd recommend, it could perfectly have a chapter explaining some changes in C since it was written.
- azharcs 16y agoI recommend Programming in C by Stephen Kochan http://amzn.to/cXnEPp http://amzn.to/cXnEPp I have also heard good things about Illustrating C
- EatenByGrues 16y agoI may be using the word 'modern' a bit liberally here, but these are all more recent than K&R at least. 'C A Reference Manual' I think is what a lot of people really want out of a C book and 'Expert C'/'C Traps and Pitfalls' both help with all of the less intuitive parts of the language that you don't really get out of K&R. C A Reference Manual http://www.amazon.com/Reference-Manual-Samuel-P-Harbison/dp/013089592X/ref=sr_1_1?ie=UTF8&qid=1289625427&sr=8-1 http://www.amazon.com/Reference-Manual-Samuel-P-Harbison/dp/... Expert C http://www.amazon.com/Expert-Programming-Peter-van-Linden/dp/0131774298/ref=sr_1_1?ie=UTF8&qid=1289625434&sr=8-1 http://www.amazon.com/Expert-Programming-Peter-van-Linden/dp... C Interfaces and Implementations http://www.amazon.com/Interfaces-Implementations-Techniques-Creating-Reusable/dp/0201498413/ref=sr_1_1?ie=UTF8&qid=1289625475&sr=8-1 http://www.amazon.com/Interfaces-Implementations-Techniques-... C Traps and Pitfalls http://www.amazon.com/C-Traps-Pitfalls-Andrew-Koenig/dp/0201179288/ref=sr_1_1?ie=UTF8&s=books&qid=1289625457&sr=8-1 http://www.amazon.com/C-Traps-Pitfalls-Andrew-Koenig/dp/0201...
- codefisher 16y agoThe book I have is "C A reference Manual" by Harbison and Steele. The advice I got when I had to buy one or other for a course I was doing that it covered much the same stuff, just assumed you had some background in programming.
- drallison 16y agoK & R, V2. Mandatory reading for anyone who programs, IMHO. Still modern at 22.