Skip to main content

The Hardest Problem in Programming Is Resisting the Temptation of the Evil Nigger - Terry Davis on Software Development

·
Categories Linux FOSS Issues
Tags TempleOS
Table of Contents

Terry Davis - The Hardest Question In Programming

This is the question Google will ask you in an interview. You must answer.

Transcript Translation
#

You must answer: is this the temptation of the evil nigger, or God’s holy wisdom?

That is my question. Uh, I will stop here and leave the rest for you to answer.

You know Google asks interview questions, and the problem I encounter at work is: is this the temptation of the evil nigger?

Is this too much black magic for our mission statement? Our mission in developing this system is to become a modern version of the Commodore 64.

Is this black magic? This is…… this is…… this is black magic.

The question is: is this black magic? This is the hardest question you may encounter in programming.

Here, this is the hardest question. This is the hardest question in programming.

For the temple of the next ten centuries, is this too much black magic?

(For the coined words niggerlicious and voodoo, I did not know how to translate them. Google suggested this is “the evil nigger is tempting you”, so I adopted that.)

Interpretation
#

Some people believe the meaning of Terry Davis’s unclear passage above is: is your code too complex, to the point that it cannot achieve its original purpose, and will people in the future be unable to understand it?

(Note: the title of this article is slightly exaggerated and modified. This sentence is not Terry Davis’s direct meaning.)

When writing programs, we should be careful not to complicate things. If we can use the simplest solution, use it.

In the video, the problem Terry Davis is solving is a HolyC loop.

His goal is to use a switch statement inside a for loop to print numbers, but with a special requirement: add brackets [ and ] before and after the interval from numbers 3 to 6.

The expected output should look something like this:

0 1 2 [ 3 4 5 6 ] 7 8 9

He brings up this example because in the code in the video, he tries writing it like this:

switch [i] {
    case 0: ... break;
    case 1: ... break;
    case 2: ... break;
    start:       // label
       '[';      // he wants to print the left bracket before entering case 3
    case 3: ... break;
    case 4: ... break;
    case 5: ... break;
    case 6: ... break;
    end:         // label
       ']';      // he wants to print the right bracket after case 6 ends
       break;
    case 7: ...
}

The problem is that the low-level operating mechanism of switch involves the C language’s low-level branch table (Jump Table). When i equals 3, the program directly jumps to the memory address of case 3. This means the code written above case 3 is skipped. The CPU does not pass through there; it directly goes to case 3. This code sandwiched between case blocks is called Dead Code in C language logic. Unless you use a very dirty goto instruction, there is no way to get there.

Generally speaking, if one wants to add brackets [ and ] before and after the interval from numbers 3 to 6, most programmers would write a pile of if (i==3) print("[") statements or split the loop apart. But Terry Davis believed this destroyed the symmetry and simplicity of the switch statement.

In addition, what he was thinking about was how the system compiler should be implemented in order to solve this seemingly simple logic problem. Why is the logic that code appears to have to human intuition different from the result of actual machine operation? If solving only the problem of printing brackets in order requires modifying the compiler’s low level and making things more complicated, then…

Therefore, the huge string of stuff in the video is actually referring to the problem of programming principles.

When developing TempleOS, Terry Davis constantly emphasized the importance of clean software code, ensuring people in the future could understand it. He also has another famous quote:

An idiot admires complexity, a genius admires simplicity.

Related


Thank you for reading. Public comments are not available on this website. I write to explore ideas honestly, not to chase social engagement or traffic. I would be glad to hear your thoughts after reading the article with care. If you found any errors, technical issues, or would like to share feedback, feel free to contact me via the email listed on the About page.