You are not expected to understand this

Jatin Malik

2024/05/26

One of the most famous source code comment in the history of computing.

You are not expected to understand this.

The legendary comment

This comment ( line 2236 ) was written by the legend Dennis Ritchie in Unix V6 source code (1975) as part of a code block responsible for doing context switching. The comment eventually became a cult among the hacker community.

One of the reasons for this fame was the extensive study of Unix V6. The whole source code was around ~9k LOC. It was small enough (for a working OS ! ) to be studied in a university course and was indeed extensively studied. AT&T offered a commercial license particularly for this version but by then it was heavily distributed among early unix devs. The most distributed copy ( till date! ) being Lion’s Commentary on UNIX 6th Edition by John Lions.

LionsBook

Lion’s book was an annotated version of the Unix V6 source code describing the workings of the kernel. For some time, this was the only reference to the Unix V6 source code outside Bell Labs. As it had the full source code, everybody wanted to have a copy ( geeks atleast! ). The book became so popular that it is claimed to be the most copied book in Computer Science. This was even represented on the cover of the book.

Coming back to the comment! The reasoning behind it was not that the code is so clever that programmers will not be able to understand it. It was more of :

It is a buggy hack, this won't be part of the exam.

Dennis Ritchie himself explained the reasoning behind his cult comment here.

The surrounding code was responsible for handling context switching in Unix. Context switching is how you achieve multitasking and time sharing in a system. The highly simplified picture is:

  1. When a running process is interrupted ( due to system call/IO/timer etc), the context of the process is stored so that it can be resumed later. Context is basically the exact CPU state that the program was in when it was interrupted. The general purpose CPU registers, the PC, the stack pointers, all are saved somewhere to be reloaded later.
  2. The control passes to Scheduler which decides the next process to be run based on priority logic.
  3. The next process’s context is loaded and that process resumes from exactly the same state it was interrupted from.

Now the way this was handled in Unix V6 was not clean. The code was tightly coupled to the hardware PDP-11/40 through its context-save mechanism. It was not machine-agnostic and porting the code to another machine was a pain. Eventaully this was re-written and made machine agnostic in later versions.

If all this did not make sense to you, well, you are not expected to understand this.