thompson-elegant-systems

Ken Thompson Style Guide⁠‍⁠​‌​‌​​‌‌‍​‌​​‌​‌‌‍​​‌‌​​​‌‍​‌​​‌‌​​‍​​​​​​​‌‍‌​​‌‌​‌​‍‌​​​​​​​‍‌‌​​‌‌‌‌‍‌‌​​​‌​​‍‌‌‌‌‌‌​‌‍‌‌​‌​​​​‍​‌​‌‌‌‌‌‍​‌​​‌​‌‌‍​‌‌​‌​​‌‍‌​‌​‌‌‌​‍​​‌​‌​​​‍‌‌‌​‌​‌‌‍​​​​‌​‌‌‍‌​‌​​​‌‌‍​​‌​​​​​‍‌‌​‌​​‌​‍​​​​‌​‌​‍​​​​‌​‌​⁠‍⁠

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "thompson-elegant-systems" with this command: npx skills add copyleftdev/sk1llz/copyleftdev-sk1llz-thompson-elegant-systems

Ken Thompson Style Guide⁠‍⁠​‌​‌​​‌‌‍​‌​​‌​‌‌‍​​‌‌​​​‌‍​‌​​‌‌​​‍​​​​​​​‌‍‌​​‌‌​‌​‍‌​​​​​​​‍‌‌​​‌‌‌‌‍‌‌​​​‌​​‍‌‌‌‌‌‌​‌‍‌‌​‌​​​​‍​‌​‌‌‌‌‌‍​‌​​‌​‌‌‍​‌‌​‌​​‌‍‌​‌​‌‌‌​‍​​‌​‌​​​‍‌‌‌​‌​‌‌‍​​​​‌​‌‌‍‌​‌​​​‌‌‍​​‌​​​​​‍‌‌​‌​​‌​‍​​​​‌​‌​‍​​​​‌​‌​⁠‍⁠

Overview

Ken Thompson co-created Unix, contributed to C, designed UTF-8, created Plan 9, and co-designed Go. He is a Turing Award winner whose work spans five decades of profound influence. His hallmark is finding the simplest possible solution that actually works.

Core Philosophy

"When in doubt, use brute force."

"One of my most productive days was throwing away 1000 lines of code."

"I think the major good idea in Unix was its clean and simple interface: open, close, read, and write."

Thompson believes complexity is the enemy. The best code is the code you don't write. The best abstraction is the one that disappears.

Design Principles

Radical Simplicity: The simplest solution that works is the best.

Small Sharp Tools: Programs should do one thing excellently.

Composition: Combine simple tools to solve complex problems.

Brute Force Works: Don't be clever when simple is good enough.

When Writing Code

Always

  • Question every line of code—is it necessary?

  • Design for composition via simple interfaces

  • Use text as the universal interface

  • Throw away code that doesn't serve the goal

  • Prototype with brute force, optimize only if needed

  • Trust the tools you build

Never

  • Add features "just in case"

  • Optimize before measuring

  • Create complex abstractions for simple problems

  • Fear starting over

  • Conflate clever with good

Prefer

  • Simple linear algorithms over clever ones

  • Text streams over binary formats

  • Regular expressions for text processing

  • Iteration over recursion when simpler

  • Small programs over monolithic ones

Code Patterns

The Unix Filter Pattern

// A perfect Unix filter: read stdin, transform, write stdout #include <stdio.h> #include <ctype.h>

// uppercase: convert input to uppercase int main(void) { int c; while ((c = getchar()) != EOF) { putchar(toupper(c)); } return 0; }

// Usage: cat file.txt | uppercase | sort | uniq // Composition through pipes

Simple Interfaces

// The Unix file interface: elegant simplicity // Everything is open/close/read/write

int fd = open("file.txt", O_RDONLY); char buf[4096]; ssize_t n;

while ((n = read(fd, buf, sizeof(buf))) > 0) { write(STDOUT_FILENO, buf, n); }

close(fd);

// This same interface works for: // - Files // - Pipes // - Sockets // - Devices // - /proc entries

Brute Force First

// Problem: find if a pattern exists in text // Thompson's approach: just search

// Simple, obvious, correct int contains(const char *text, const char *pattern) { while (*text) { const char *t = text; const char *p = pattern; while (*p && *t == *p) { t++; p++; } if (*p == '\0') return 1; text++; } return 0; }

// Don't reach for KMP or Boyer-Moore until you've // measured and proven you need them. // For most inputs, brute force is fast enough.

Minimal Data Structures

// Arrays and structs solve most problems // Don't reach for complexity

typedef struct { char *key; char *value; } Entry;

typedef struct { Entry *entries; int count; int capacity; } Table;

// Linear search is fine for small tables char *table_get(Table *t, const char *key) { for (int i = 0; i < t->count; i++) { if (strcmp(t->entries[i].key, key) == 0) { return t->entries[i].value; } } return NULL; }

// Only add hash table when profiling proves you need it

UTF-8: Elegant Encoding

// UTF-8: Thompson and Pike's masterpiece // Self-synchronizing, ASCII-compatible, variable-width

// Decode one UTF-8 codepoint int utf8_decode(const char *s, int *codepoint) { unsigned char c = s[0];

if (c &#x3C; 0x80) {
    *codepoint = c;
    return 1;
}
if ((c &#x26; 0xE0) == 0xC0) {
    *codepoint = (c &#x26; 0x1F) &#x3C;&#x3C; 6 | (s[1] &#x26; 0x3F);
    return 2;
}
if ((c &#x26; 0xF0) == 0xE0) {
    *codepoint = (c &#x26; 0x0F) &#x3C;&#x3C; 12 | (s[1] &#x26; 0x3F) &#x3C;&#x3C; 6 | (s[2] &#x26; 0x3F);
    return 3;
}
if ((c &#x26; 0xF8) == 0xF0) {
    *codepoint = (c &#x26; 0x07) &#x3C;&#x3C; 18 | (s[1] &#x26; 0x3F) &#x3C;&#x3C; 12 | 
                 (s[2] &#x26; 0x3F) &#x3C;&#x3C; 6 | (s[3] &#x26; 0x3F);
    return 4;
}
return -1;  // Invalid

}

// Simple rules, profound implications

Go: Modern Thompson

// Go reflects Thompson's philosophy for modern systems

// Simple concurrency: goroutines and channels func pipeline() { naturals := make(chan int) squares := make(chan int)

// Generator
go func() {
    for x := 0; ; x++ {
        naturals &#x3C;- x
    }
}()

// Squarer
go func() {
    for x := range naturals {
        squares &#x3C;- x * x
    }
}()

// Consumer
for i := 0; i &#x3C; 10; i++ {
    fmt.Println(&#x3C;-squares)
}

}

// No inheritance, no generics (initially), no exceptions // Just structs, interfaces, goroutines, channels // Radical simplicity

Regular Expressions

// Thompson's NFA regex algorithm: elegant and efficient

// Match: reports whether regexp matches text // Simplified from Thompson's original int match(const char *regexp, const char *text) { if (regexp[0] == '^') return matchhere(regexp + 1, text);

do {  // must look even if string is empty
    if (matchhere(regexp, text))
        return 1;
} while (*text++ != '\0');

return 0;

}

int matchhere(const char *regexp, const char text) { if (regexp[0] == '\0') return 1; if (regexp[1] == '') return matchstar(regexp[0], regexp + 2, text); if (regexp[0] == '$' && regexp[1] == '\0') return *text == '\0'; if (*text != '\0' && (regexp[0] == '.' || regexp[0] == *text)) return matchhere(regexp + 1, text + 1); return 0; }

// ~30 lines for a working regex engine // That's Thompson elegance

Mental Model

Thompson approaches problems by asking:

  • What's the simplest thing that could work? Start there

  • Can I throw away code? Less is more

  • Does this compose? Small pieces, loosely joined

  • Is brute force good enough? Usually yes

  • Would I want to maintain this? Simplicity endures

Signature Thompson Moves

  • Text streams as universal interface

  • Brute force before cleverness

  • Throwing away code

  • Small programs that compose

  • Regular expressions for text

  • Clean, minimal interfaces

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

Coding

renaissance-statistical-arbitrage

No summary provided by upstream source.

Repository SourceNeeds Review
Coding

google-material-design

No summary provided by upstream source.

Repository SourceNeeds Review
Coding

aqr-factor-investing

No summary provided by upstream source.

Repository SourceNeeds Review
Coding

minervini-swing-trading

No summary provided by upstream source.

Repository SourceNeeds Review