Customer Reviews

29
3.5 out of 5 stars
21st Century C: C Tips from the New School
Format: PaperbackChange
Price:$28.49 + Free shipping with Amazon Prime
Your rating(Clear)Rate this item


There was a problem filtering reviews right now. Please try again later.

146 of 153 people found the following review helpful
Format: Paperback
The C programming language is alive and well: it is used not only in vast amounts of legacy code but also in new development, often when efficiency is important and the learning curve imposed by C++ is deemed unacceptable. As for the literature on C, the standard high-quality text is the one by Kernighan & Ritchie (K&R), while the "second book" genre doesn't have too many representatives. Peter van der Linden's "Expert C programming: Deep C Secrets" and David Hanson's "C Interfaces and Implementations" are probably the best choices (perhaps supplemented by P. J. Plauger's "The Standard C Library"). However, given that all these books date from the 1990s or earlier, a book on modern C programming was sorely needed.

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[3] and then talks about &list as if he's already explained what that means (when he's only discussed list and &list[0]). 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.

Alex Gezerlis
55 commentsWas this review helpful to you?YesNoSending feedback...
Thank you for your feedback.
Sorry, we failed to record your vote. Please try again
Report abuse
28 of 35 people found the following review helpful
on January 31, 2013
Format: PaperbackVerified Purchase
It's sort of amusing to read all the cranky one-star reviews of this book: "Why would you need a book? Just read the manpages!" "Real men don't use libraries or Autoconf!" "Go back to Ruby and Python you young whippersnappers!" "I don't like macros!" "Get off my lawn with your rock 'n roll and C11 (and C99)!" Wow, did the author graffiti an old folks' home or something?

Here on Earth, this book does for C what dozens of books have done for more modern languages like Ruby or C#. The book shows an intermediate to experienced coder in other languages how to hit the ground running in C. Since C is not exactly like those "other" languages, the advice isn't and shouldn't be the same as for those. You do have to deal with makefiles, and this book will show you several ways to do so. You can't avoid pointers, so he shows you how without pretending that pointers are deep mysterious difficult voodoo. C is not a "batteries included" language, so this book describes several libraries that you should use rather than e.g. implementing linked lists or Unicode handling from scratch by yourself.

By the same token, it's 2013 and C shouldn't be coded the exact way I was taught at university in 1995. Designated initializers prevent errors and make code easier to read. You don't need malloc() for runtime array sizing. It's fine to declare variables where they're used rather than at the top of the scope. Variadic functions are both underpowered and dangerous, but we can use them productively and safely with intelligently written macros using __VA_ARGS__. You still have to manage your own memory in C, but now there is Valgrind, the use of which this book illustrates clearly in a page and a half. Oh yeah, and we have libraries now, so you don't need to malloc() constantly while handling strings either.

I'm actually surprised none of the one-star fogies complained about all the struct-passing, of which I hadn't seen much before and of which there is a great deal in this book. I mean, if compilers in the 1980s only let you stuff so much on the stack, dooming us to ampersands and memory leaks, why should we acknowledge we have better compilers today? I almost suspect they haven't actually read the book...

It's your loss if my snark offends you. The author of this book is opinionated too. He quotes dissident punk bands with vulgar names at the beginning of chapters. He has specific recommendations for what tools to use and how to use them. In case you need convincing not to hobble yourself with an IDE, he shows you why a decent editor and the command line is better. He doesn't tell you how to use M$ tools because they suck (e.g. they're stuck forever on C89). The dozens of oddball build tools that have cropped up to replace make have failed to do so, and make is demonstrated repeatedly here to show you why.

I love K&R, but the world has changed since 1989, and this is the first C book I've read that realizes that.
11 commentWas this review helpful to you?YesNoSending feedback...
Thank you for your feedback.
Sorry, we failed to record your vote. Please try again
Report abuse
8 of 9 people found the following review helpful
Format: Paperback
Disclaimer: I've received this book as a part of the O'Reilly Blogger Review Program.

In 21st Century C, Ben Klemens sets out to show you how much C has changed over the past two decades. Promising to show you how to make the most of modern C, he takes on a tour of the language, including features added by recent standards, and also indicates what features we should stop using.

Verdict: [|||||| ] (6 out of 10)

tl;dr - I wouldn't recommend this book in general. If you're looking for idiomatic C, and you're experienced enough with C to know what works and what doesn't, and are able to make judgment on a case-by-case basis with regards to the author's advice, you might be able to find a few interesting gems in here.

For the reader interested in a more detailed review:

I found Klemens' writing to be entertaining. The references to punk rock became a little groan-inducing after some time, but groans are better than snores - I wasn't put to sleep by the writing. His character definitely shows through his writing. I appreciate this, as all too many text books suffer from the formalism-first problem. Readers are humans, and Klemens addresses this well.

The tour of C history was also very interesting. The coverage of C from inception up to the latest standard (C11) and how things have changed since then was especially valuable to me. I even appreciated the mild coverage that was given regarding C on Windows, where C really seems to be an afterthought.

One more good point before I jump into the criticisms - the chapter covering pointer semantics was solid. Klemens explains how to use them, several of the associated gotchas, and what to look out for. Succinct, clear, and full of examples.

Things are not so bright every where in the book. One particular section that concerned me, was in Chapter 1: The Unified Header. Klemens contends that every project should use an "allheaders.h" because "Your compiler doesn't think 2,400 lines is a big deal any more, and this compiles in under a second". While I agree that compilation speed won't be a problem, the unified header approach has a few problems that are more troublesome for long-term maintenance. First and foremost, since C has very limited support for name-spacing, it'll be very difficult to new comers to your C library to determine where each imported function and structure comes from. When time to refactor comes along, it'll be more likely that the refactoring process will be difficult if the reader follows this unified header approach than if they made more clear separation of their modules by purpose, relationship, and abstraction level.

I leave you with this final note - one of the strengths of this book is that it is very opinionated. Unfortunately, this is also this book's greatest weakness. Take every claim made within with a grain of salt and you should emerge wiser.
0CommentWas this review helpful to you?YesNoSending feedback...
Thank you for your feedback.
Sorry, we failed to record your vote. Please try again
Report abuse
14 of 18 people found the following review helpful
on January 19, 2013
Format: Kindle Edition
From the point of C and C++ programmer in the past. Scala, Groovy and Perl in present.
Quite many things presented in the book are debatable topics. Because of that, I believe, most of the harsh ratings earned by earlier reviews are the consequences of the author's view not being in sync with reviewers preferences.
There is no Single Right Way to write C code. The book is not a definitive guide and does not pretend to be so.
There is no wrong advice given in the book either. Chapters about Packaging, Testing, and Version Control are surely an essential additions.
It is fast to read, may give you some new insights or, even if you disagree, alternative views on C coding practices. In the end - the choice is yours, to use the macros or to not, how terse should your code be, etc. Together with some classic C book, this is a good book for a beginner. Some tricks may be refreshing even for a seasoned C programmer, though.
11 commentWas this review helpful to you?YesNoSending feedback...
Thank you for your feedback.
Sorry, we failed to record your vote. Please try again
Report abuse
23 of 34 people found the following review helpful
on November 6, 2012
Format: Paperback
I have been programming in C for nearly 30 years, mostly embedded systems and have recently starting looking at Linux programming. This book brings together information that I am sure is available online but puts it together in the correct order if you want to start doing serious C development. It stars with how to correctly setup you environment and covers tools and techniques like make files, package managers, version control (git), and writing your code so it can be more easily interface into other languages. Really Part One is worth the price of admission.

The second Part is a refresher for current C programers about what has changed over the years and how to use the C99 and later compilers, which I am finding very useful. While older users may see religious arguments within some of these chapters, I found most to very well reasoned and very helpful. The sections on scoping rules, the use of const, and the chapter on Object Oriented Programming in C are very useful.

If you don't already know the C language you may not get the full use of the book on first reading but I can totally recommend it after you have the basics down and for experienced programmers I can guarantee you will find some nuggets of new wisdom.

I purchased the eBook directly from O'Reilly but this would make a good bed-side reader if you get the paper version.
11 commentWas this review helpful to you?YesNoSending feedback...
Thank you for your feedback.
Sorry, we failed to record your vote. Please try again
Report abuse
1 of 1 people found the following review helpful
on August 11, 2014
Format: Paperback
It would benefit from splitting into two books: one for beginners another one for folks with 20+ years of experience looking for good overview of the new stuff. Otherwise it is a pretty decent book with a lot of interesting stuff and good ideas to think about.
0CommentWas this review helpful to you?YesNoSending feedback...
Thank you for your feedback.
Sorry, we failed to record your vote. Please try again
Report abuse
4 of 6 people found the following review helpful
on May 7, 2013
Format: Paperback
21st Century C is a useful read for the budding Linux hacker, especially due to its focus on the GNU toolchain. Among its highlights is the constant reminder of improvements to the C language since the original ANSI C standard (C89). It covers a wide range of topics, you may want to skim particular topics and return to them when you see the need.

The book is divided into two parts. Part 1 starts with mundane things like installing a C compiler and compiling your C program. It then moves on to useful topics such as debugging using GDB, checking for errors using Valgrind, unit testing, building documentation using Doxygen and CWEB, and packaging your project using Autotools. If you have executed "./configure" and then "make install", but never looked under the hood, now is the time to do that. The chapter on version control using Git is probably the best coverage of Git I have seen in any book.

Part 2 focuses on the C language itself. This part starts with coverage of pointers, followed by a chapter on C syntax that programmers should avoid. The following chapters discuss usage of macros to write succinct code, text handling, and better structs and typedefs. The chapter on object oriented programming delves into using anonymous structs for extending objects, function pointers, and building and freeing objects. The final chapter wraps up by introducing several popular open source libraries such as GLib, POSIX, GSL, SQLite, libxml, and cURL.

You can cobble together the knowledge dispensed in this book by reading manuals and articles over the internet, but it is convenient to have it all together in one place to be read at your leisure.
0CommentWas this review helpful to you?YesNoSending feedback...
Thank you for your feedback.
Sorry, we failed to record your vote. Please try again
Report abuse
1 of 1 people found the following review helpful
on November 12, 2014
Format: Paperback
Description of the "make" tools is great. This book is at the right level to read through quickly and refresh your memory on various aspects of C programming for portability.
0CommentWas this review helpful to you?YesNoSending feedback...
Thank you for your feedback.
Sorry, we failed to record your vote. Please try again
Report abuse
6 of 9 people found the following review helpful
on January 13, 2013
Format: Paperback
Perhaps I am just the right audience for the book (programmer but don't use C much anymore because I have moved on to more "modern languages") but I found the book enjoyable despite some other reviewers comments. Some of the material I already knew but some was new and the information provided was enough to get me started (more detail can always be found online). I think some of the reviewers critical comments come from the expectations that the book could have never met (because of the title). I can imagine and would purchase a 21st century C book that is a thousand pages longer and comprehensive. This is a short taste of some updated practices and advice.
0CommentWas this review helpful to you?YesNoSending feedback...
Thank you for your feedback.
Sorry, we failed to record your vote. Please try again
Report abuse
12 of 18 people found the following review helpful
on November 24, 2012
Format: Paperback
I'm an advanced C programmer and was hoping for an update on some of the latest in C99, C11, and the state of the art in general. Unfortunately, this book just didn't do it for me. It's definitely not meant for beginners as so much is assumed, but it's too sloppy with too many mistakes to be useful for experts. On top of that, the author gives a lot of really bad advice that any advanced user would just laugh at.

Bottom line, skip this one.
22 commentsWas this review helpful to you?YesNoSending feedback...
Thank you for your feedback.
Sorry, we failed to record your vote. Please try again
Report abuse
     
 
Customers who viewed this also viewed
21st Century C: C Tips from the New School
21st Century C: C Tips from the New School by Ben Klemens (Paperback - October 12, 2014)
$45.97

Expert C Programming: Deep C Secrets
Expert C Programming: Deep C Secrets by Peter van der Linden (Paperback - June 24, 1994)
$34.73

Understanding and Using C Pointers
Understanding and Using C Pointers by Reese M. Richard (Paperback - May 18, 2013)
$36.39
 
     

Send us feedback

How can we make Amazon Customer Reviews better for you?
Let us know here.

Your Recently Viewed Items and Featured Recommendations 
 

After viewing product detail pages, look here to find an easy way to navigate back to pages you are interested in.