Shikhil Saxena

Sep 19, 2025 • 1 min read

How to Write Garbage Code’ (by Linus Torvalds

🧠 Core Message: Optimize for Cognitive Load

Linus Torvalds harshly criticized a pull request for adding a helper function that made code less readable, not more. His main point? Code should be obvious and self-contained, not abstracted to the point of confusion.

“If you write (a << 16) + b, you know what it does. If you write make_u32_from_two_u16(a, b), you don’t.”

🧩 Key Takeaways

1. PRY > DRY (Please Repeat Yourself)

  • Duplication isn’t always bad.

  • Repeating simple logic can reduce mental overhead.

  • Abstracting everything into helpers increases “micro-context switches.”

2. Cognitive Load Matters

  • Every helper function, file jump, or abstraction costs brainpower.

  • Humans and LLMs have limited working memory — fewer “chunks” = better clarity.

3. Locality of Reference

  • Keep related logic close together.

  • Easier for humans and AI tools to understand and refactor.

4. Premature Optimization Is Costly

  • With modern IDEs and LLMs, refactoring is cheap.

  • Don’t abstract early — optimize for clarity first.

5. Tone Matters

  • Linus’s technical critique was valid, but his delivery was harsh.

  • The author reminds us: “It doesn’t cost anything to be nice.”

💡 Final Thought

Clean code isn’t just about elegance — it’s about reducing friction for future readers. Sometimes, repeating yourself is the kindest thing you can do for your teammates (and your future self).

Join Shikhil on Peerlist!

Join amazing folks like Shikhil and thousands of other builders on Peerlist.

peerlist.io/

It’s available... this username is available! 😃

Claim your username before it's too late!

This username is already taken, you’re a little late.😐

0

6

1