- Paperback: 296 pages
- Publisher: O'Reilly Media; 1 edition (November 5, 2012)
- Language: English
- ISBN-10: 1449327141
- ISBN-13: 978-1449327149
- Product Dimensions: 7.1 x 0.6 x 9 inches
- Shipping Weight: 1.1 pounds
- Average Customer Review: 32 customer reviews
- Amazon Best Sellers Rank: #1,279,394 in Books (See Top 100 in Books)
Enter your mobile number or email address below and we'll send you a link to download the free Kindle App. Then you can start reading Kindle books on your smartphone, tablet, or computer - no Kindle device required.
To get the free app, enter your mobile phone number.
21st Century C: C Tips from the New School 1st Edition
Use the Amazon App to scan ISBNs and compare prices.
Customers who viewed this item also viewed
What other items do customers buy after viewing this item?
Q&A with "21st Century C" author Ben Klemens
"C has no corporation or foundation pushing it, no trademarked logos, no ad budget, and no designers on perpetual book tour. It's just a simple, fast language."
O'Reilly Media: What made you write the book?
Ben Klemens: I kept having the same conversation, with the same disconnect. I would talk about how I was having an easy time writing code in C, and the person I was talking to would tell me that doing so is impossible, because everything needs to be written from scratch and there is endless declaration and memory management cruft obscuring the real flow of the code. Finally, I got a friend to concede that maybe I wasn't hallucinating, and maybe I really was writing C code in reasonable time and with reasonable clarity, and he asked me, "OK, so can you refer me to a textbook that teaches C with a modern style?" And finally, I understood the disconnect, because I couldn't find such a text. Everything I read was at least a decade old and had a section teaching you how to re-implement linked lists yet again. The C standard was revised in 1999, allowing for a much more flowing writing style, yet these books still presented code with a halting and obtuse style.
ORM: Why is your book especially important now?
BK: I should've written it five years ago.
ORM: What is on the horizon for your readers?
BK: I have it easy here, because C is still immensely common. You can find measures that say that it is the most popular computing language, and some that rank it at maybe No. 2 or No. 3. What makes this amazing about our 40-year-old friend is that it has no corporation or foundation pushing it, no trademarked logos, no ad budget, and no designers on perpetual book tour. It's just a simple, fast language. And it's not going away very quickly. I have no idea what we'll be writing 50 years from now, but I'm pretty confident that in five or 10 years, we'll still be writing a lot of C code. Also, C is still the lingua franca of computing. So many languages have a back door that lets you write some code in C, so even people who long ago decided to avoid C eventually find themselves writing little snippets in it.
By the way, I'm obviously a satisfied user, but I come neither to praise or to bury C. The language has warts, many of which I point out in the book along the way to pointing out its better features.
ORM: What is the single most important take-away from your book?
BK: Use libraries. If you don't know how to link to a binary tree library, you are doomed to write your own binary tree implementation. I think a lot of the people who think everything in C has to be written from scratch have just never learned how to reliably link their code to the wealth of existing libraries.
ORM: Who is your intended audience?
BK: I have two.
- People who only know a smattering of C, which they picked up on the street.
- People who learned C from a more traditional textbook, and know that they need to update from how C was written in the 1980s. Probably included here are CS majors who were traumatized by their college C textbook and decided they hate C, that it is an unmerciful disaster, and so begins a downward spiral where they avoid writing in C, so when they do have some C-based problem it is a melancholy burden, so after getting that done they avoid writing any more C for as long as possible and thus their skills get rustier. This book can help to break the cycle.
About the Author
Ben Klemens has been doing statistical analysis and computationally-intensive modeling of populations ever since getting his PhD in Social Sciences from Caltech. He is of the opinion that writing code should be fun, and has had a grand time writing analyses and models (mostly in C) for the Brookings Institution, the World Bank, National Institute of Mental Health, et al. As a Nonresident Fellow at Brookings and with the Free Software Foundation, he has done work on ensuring that creative authors retain the right to use the software they write. He currently works for the United States Federal Government.
Browse award-winning titles. See more
Top customer reviews
There was a problem filtering reviews right now. Please try again later.
As far as C is concerned, it's a decent introduction to the relatively recent additions to the language. Once you've internalized K&R, this book is a next step.
As a programmer who read K&R years ago, wrote some C programs in college, and occasionally implements C extensions for scripting languages, I found this book very informative. I very rarely even look at C, but have an interest in using the language more. I feel well prepared for starting down that path after reading this text.
The Good: Ben Klemens' "21st Century C" is a text that assumes some knowledge of classic C and attempts to expand and update that knowledge. This has allowed the author to write a book that is not too long and can thus be read cover-to-cover. Even though this is not an elementary tutorial, the author has also included overviews of some basic concepts to make sure everyone's on board. The writing is for the most part pleasant enough and sometimes even humorous, e.g. "If you and a friend both have v1 [...] Or, if you have no friends". The code for the complete programs shown in the text has been packaged and is available on the publisher's website. Almost all of these programs are easy to compile and run -- this should go without saying, but unfortunately many books are rushed out too soon. One attractive aspect of this volume is that it contains a grab bag of tips (e.g. a function that takes in a pointer to void should immediately assign that to an appropriately typed pointer) as well as welcome summarizations of related topics, bringing to mind books like "Effective C++" and "Effective Java". For example, chapter 6 includes a useful table that goes over valuable aspects of static, automatic, and allocated storage duration (though Klemens doesn't use the standard terms "allocated" and "storage duration" but speaks instead of a "manual memory model"). A cute trick is given soon thereafter, in the form of a macro to initialize a static variable with a nonconstant value. More good macro material is included in later chapters, leading to convenient string-handling or helping us write functions that take in a variable number of named arguments. In the process of doing the latter, Klemens drives home a fun idiom: first define a struct, then define a variadic macro that puts its arguments inside a struct, and finally write a function that takes in a single struct as input. The main selling point of this text is that it's quite up-to-date, repeatedly mentioning C99 and C11. Importantly, the modern C features are not an afterthought but are used throughout the volume. Even so, chapters 9-12 would be the ones most useful to a reader unfamiliar with tools like strtok_s, designated initializers, the _Generic keyword, and anonymous unions. The last 2.5 chapters also attempt to inch toward programming in the large, with Klemens doing things like implementing a dictionary and using libraries (e.g. GSL and GLib) repeatedly. Speaking of libraries, Part I is dedicated to the modern ecosystem around C and is a charming departure from the language-centeredness of most programming books. Apart from giving basic usage info on debugging, Makefiles, and version control software, Klemens also introduces sleek tools like seq, pkg-config, and screen. One way to test an author's pedagogical skills is to evaluate a section containing material one is completely unfamiliar with. For me that applied to the sections on git rebase and on the variables appearing in Makefile.am; in both cases I felt the selection of topics as well as the explanations were nicely done.
The Bad: I begin by discussing structural problems and then go on to cover detailed issues. Klemens mentions in the Preface that "about a third of this book has almost no C code in it." First of all, Part I takes up 100 pages and Part II 150, so it's not really one third. Second, placing the non-C-specific material first leads to an excessive number of forward references. One example: p. 40 constructs the unit tests for a piece of code, p. 72 shows an Automake file that handles that testing, while the C program itself is introduced on p. 212. A related structural/misplacement issue has to do with Klemens' decision to introduce modern C features in chapter 10 (of 12). This wreaks havoc, given that he has (to his credit) opted to use new entities (like designated initializers and compound literals) throughout the text, even if he sometimes doesn't say he's doing so. Turning now to detailed issues, it's worth noting that the book contains many mistakes which are not just first-printing-typos, but flat-out factual errors. Here are a few examples, all drawn from a small fraction of the book: Klemens says that sources in distutils.core.Extension is "an array", even though it is a list of strings; he alleges that the stack size on Linux is limited to 2 or 3 megabytes -- stating this in apparent ignorance of the existence of ulimit and setrlimit; embarrassingly, the first use of pointers in the chapter on pointers contains at least two mistakes in one line (which is shown twice); he confusedly states that "the syntax for a function type is really a pointer to a function of a given type" -- this would mean that we could have array elements that are of function type, which is patently untrue. In other cases, the writing is slipshod: Klemens mentions "a local variable with static linkage" even though there is no such thing as static linkage in C (there's only external, internal, and none); he devotes an entire section to setting the array size at runtime but fails to note that variable-length arrays became optional in C11 -- later on, he can't make up his mind if such arrays can be initialized or not; he counterposes open to "the POSIX fopen" and refers to a "C-standard get_opt function"; he thinks he's uncovered a contradiction in K&R (just to be clear: he hasn't) but can't even be bothered to make the elementary distinction between declarations and definitions; the catalog of such issues is simply too long. In yet other cases, the text is characterized by plain old poor pedagogy, e.g. he defines list and then talks about &list as if he's already explained what that means (when he's only discussed list and &list). On a different note, we get a chapter on extending Python with C, but almost nothing on the impact of C/C++ feature differences. Bjarne Stroustrup has written an interesting article on C and C++'s "sibling rivalry" (which Klemens does not cite). Speaking of Stroustrup, the bibliography's only reference to "The C++ Programming language" is dated 1986 (presumably meaning the 1st edition). It's also worth noting that the bibliography includes two texts by Scott Meyers that are not cited in this book, but no reference to the volume by van der Linden that is the obvious competition in this niche.
In a nutshell, I liked the premise of the book much more than I enjoyed the execution. It was disappointing to see Part II start out by mentioning "especially complicated pointer setups like pointers to functions" only to repeatedly mishandle them near its end (both in the text and in the code). It should be noted that K&R managed to thoroughly discuss function pointers in one short section. Yes, expecting an author to match the quality of K&R is holding him to an impossible standard. But expecting him to write an authoritative and well-structured second book on C isn't as exacting. All in all, three stars.