C Is Punk Rock
C has only a handful of keywords and is a bit rough around the edges, and it rocks. You can do anything with it. Like the C, G, and D chords on a guitar, you can learn the basic mechanics quickly, and then spend the rest of your life getting better. The people who dont get it fear its power and think it too edgy to be safe. By all rankings, it is consistently the most popular language that doesnt have a corporation or foundation spending money to promote it.
Also, the language is about 40 years old, which makes it middle-aged. It was written by a few guys basically working against management the perfect punk rock origin s but that was in the 1970s, and theres been a lot of time for the language to go mainstream.
What did people do when punk rock went mainstream? In the decades since its advent in the 1970s, punk certainly has come in from the fringes: The Clash, The Offspring, Green Day, and The Strokes sold millions of albums worldwide (to name just a few), and I have heard lite instrumental versions of songs from the punk spinoff known as grunge at my local supermarket. The former lead singer of Sleater-Kinney now has a popular sketch comedy show that frequently lampoons punk rockers. One reaction to the continuing evolution would be to take the hard line and say that the original stuff was punk and everything else is just easy punk pop for the masses. The traditionalists can still play their albums from the 70s, and if the grooves are worn out, they can download a digitally mastered edition. They can buy Ramones hoodies for their toddlers .
Outsiders dont get it. Some of them hear the word punk and picture something out of the 1970s a historic artifact about some kids that were, at the time, really doing something different. The traditionalist punks who still love and play their 1973 Iggy Pop LPs are having their fun, but they bolster the impression that punk is ossified and no longer relevant.
Getting back to the world of C, we have both the traditionalists, waving the banner of ANSI 89, and those who will rock out to whatever works and may not even realize that the code they are writing would not have compiled or run in the 1990s. Outsiders dont get the difference. They see still-in-print books from the 1980s and still-online tutorials from the 1990s, they hear from the hardcore traditionalists who insist on still writing like that today, and they dont even know that the language and the rest of its users continue to evolve. Thats a shame, because theyre missing out on some great stuff.
This is a book about breaking tradition and keeping C punk rock. I dont care to compare the code in this book to the original C specification in Kernighan & Ritchies 1978 book. My telephone has 512 MB of memory, so why are our C textbooks still spending pages upon pages covering techniques to shave kilobytes off of our executables? I am writing this on a bottom-of-the-line red netbook that can accommodate 3,200,000,000 instructions per second; what do I care about whether an operation requires comparing 8 bits or 16? We should be writing code that we can write quickly and that is readable by our fellow humans. Were still writing in C, so our readable but imperfectly optimized code will still run an order of magnitude faster than if wed written comparable code in any number of alternative, bloated languages.
Q & A (Or, the Parameters of the Book)
Q:How is this C book different from all others?
A: Some are better written, some are even entertaining, but C textbooks are a somewhat uniform bunch (Ive read a lot of them, including ). Most were written before the C99 standard simplified many aspects of usage, and you can tell that some of those now in their nth edition just pasted in a few notes about updates rather than seriously rethinking how to use the language. They all mention that there might be libraries that you could maybe use in writing your own code, but most predate the installation tools and ecosystem we have now, which make using those libraries reliable and reasonably portable. Those textbooks are still valid and still have value, but modern C code just doesnt look like much of the code in many of those textbooks.
This book picks up where they left off, reconsidering the language and the ecosystem in which it lives. The storyline here is about using libraries that provide linked lists and XML parsers, not writing new ones from scratch. It is about writing code that is readable and has a friendly user interface.
Q:Who is this book for? Do I need to be a coding guru?
A: You have experience coding in any language, maybe Java or a scripting language such as Perl. I dont have to sell you on why your code shouldnt be one long routine with no subfunctions.
The body of the book assumes basic knowledge of C gained from time spent writing C code. If you are rusty on the details or are starting from zero, offers a short tutorial on basic C for readers who are coming from a scripting language like Python or Ruby.
I might as well point out to you that I have also written a textbook on statistical and scientific computing, Modeling with Data . Along with lots of details of dealing with numeric data and using statistical models for describing data, it has a longer, more standalone tutorial on C, which I naturally think overcomes many of the failings of older C tutorials.