Waggish

Information

This article was written on 17 Oct 2011, and is filed under Miscellania.

Related posts

Dennis Ritchie Tribute Part 2: Obfuscated C from Brian Westley

Dennis Potter: Blue Remembered Hills

Memorial to Dennis Ritchie and C

Dennis Ritchie’s passing got to me a lot more than Steve Jobs, and that probably serves as a fitting analogy for my tastes in literature and philosophy as well. (I’ll leave that for you all to figure out; it’s not too hard.)

Programming language design and theory is a very collaborative discipline, and Dennis Ritchie and his language C owe much to Ken Thompson (who co-created Unix with Ritchie and the family of B languages that preceded C), as well as to the team of researchers that created ALGOL  in the 1950s, which pretty much is the grandparent of all structured imperative languages today.

But C was Ritchie’s baby, and it took over the world. It’s the language that, apart from English, has had the greatest impact on my life, my thought processes, my conceptualizations. Many, many characters and punctuation have indelible associations in my mind due to C. There is probably no book in the world that I have been over in such minute detail as K&R, Brian Kernighan and Ritchie’s slim, dense, but extremely clear C reference book.

Damn you, strncpy!

I haven’t looked at it in a while now, but I remember this section from the 2nd edition preface quite well:

C is not a big language, and it is not well served by a big book. We have improved the exposition of critical features, such as pointers, that are central to C programming.

Between the theoretical world of data structures and algorithms and the practical world of assembly language and processors, C was the medium by which I (and millions of others) linked the two.

So as my sentimental memorial to Ritchie, here’s Quicksort in C (taken from Algorithmist; I chose this implementation not for its excellence but for showing off some of C’s charming syntactical idiosyncrasies–it was a contest between this one and this inline macro implementation, which easily would have won had it not been too long to include here):

/* C, hand-coded quicksort */
#include <stdio.h>
#include <stdlib.h>

typedef TYPE T;

void quicksort(T* data, int N)
{
  int i, j;
  T v, t;

  if( N <= 1 )
    return;

  // Partition elements
  v = data[0];
  i = 0;
  j = N;
  for(;;)
  {
    while(data[++i] < v && i < N) { }
    while(data[--j] > v) { }
    if( i >= j )
      break;
    t = data[i];
    data[i] = data[j];
    data[j] = t;
  }
  t = data[i-1];
  data[i-1] = data[0];
  data[0] = t;
  quicksort(data, i-1);
  quicksort(data+i, N-i);
}

2 Comments

  1. Gabriella Coleman
    17 October 2011

    Thanks for sharing. There is a nice outpouring from the tech community!

  2. Bob Irving
    17 October 2011

    Round about 2000, I had to try to convert my brain from DEC’s VMS operating system to Unix. I never made it. So rather than mourn this gentleman, I would rather that he had not existed. I suppose it was because I was taught VMS and had to acquire Unix by osmosis… Sorry!

Leave a Reply