quarta-feira, outubro 12, 2011

RIP Ritchie (1941-2011): "The C Programming Language" by Kernighan and Ritchie



(Original Review, 2011)


Along with some acclaimed hackers, Ken Thompson, Robert Pike, Brian Kernighan and Dennis Ritchie pretty much shaped the modern world of computing. The Unix/C duet is still the archetype and the measuring stick for modern operating systems and programming languages. Conciseness, control, exceptional engineering that didn't ever get old – and the ability to shoot yourself in the foot if you want so. Good stuff! And the K&R C book is truly praise-worthy. Timeless and very, very elegant.

Great memories I have with that book, trying to bit shift values in the bus people were looking really strange at me while I was holding the book and was scribbling in binary like a crazy person on the notebook... Don't think they even thought it was about Computer Science.

Some criticisms I’ve been hearing over the years regarding C:

- C has good points and bad points -- some clever ideas, and some mistakes. The lack of proper string-handling tools ...

My answer: I've always debated with myself whether to bother responding to this, but as always I can't resist. Lack of string-handling tools in C is part of the nature of the language, I don't know how that can be regarded as a mistake. And there isn't a lack of "proper" string handling tools, there is a complete lack of any string handling tools in the language itself, or even a "string" type. The C "standard library" contains a simple model of string handling based on pointers to null-terminated byte sequences. Any further models can be added as required. For instance the string handling of Perl, including Unicode, regular expressions, strings containing null bytes, garbage collection, and anything else you could want, is entirely written in C. In the same way, there is a design mistake in a hammer, that it is very hard to put a screw in with it. I've also noticed a design mistake in screwdrivers, which are no good for putting in nails, and a chisel is virtually useless for cutting a plank of wood in two. After hundreds of years of carpentry, you'd think they would have learnt by now. Since every other type in C is something which fits into a processor register, and every operation in the language has a clear translation into assembly language, I think it would be a great idea to add an abstraction like a string type to the language which neither fits into a processor register nor translates straightforwardly into assembly language. I'm also thinking of putting square wheels on my bicycle to help negotiate potholes in the road, and getting rid of those pesky brakes which keep stopping my car. Damn those design mistakes!

- expensive legacy in terms of buggy software, student learning curve, failed projects

My answer: C might have served well as a scapegoat for failed IT projects in the past, but as luck would have it, IT projects are continuing to fail disastrously without any help from C.

I’m already a bit rusty, but here’s to you Ritchie (1941-2011):

//Cenesis, chapter 1
#include
int main()
{
  puts("In the beginning, when Ritchie created the Unix and the C");
  puts("and the UNIX was without form or shape, with darkness over the abyss and a mighty wind sweeping over the waters");
  puts("Then Riche said: hello, world, and there was code");
  puts("Riche saw that the code was good. Ritchie then separated the code from the bug.");
  puts("Riche called the code \“day,\” and the bug he called \“night.\”");
  return 0;

NB: When I think about the K&R C book, I always like to compare it to a novel that gives me enough to built the details in my mind without having to ram the details down my throat.