mkirchner/linked-list-good-taste logo

mkirchner/linked-list-good-taste

Free

Linus Torvalds' linked list argument for good taste, explained

FreeFree tier
Type
Open Source

About mkirchner/linked-list-good-taste

This GitHub repository by mkirchner provides a detailed explanation of Linus Torvalds' linked list argument for good taste, as featured in a 2016 TED interview. It dissects two implementations of item removal in singly linked lists: the standard CS101 approach requiring a special case and a more elegant solution using indirect addressing (pointer-to-pointer) that eliminates the special case. The repository includes C code examples, diagrams, and extends the technique to insertion operations (insert_before). It serves as an educational resource for understanding pointer tricks and improving coding elegance.

Key Features

Explains two implementations of singly linked list item removal
Demonstrates indirect addressing (pointer-to-pointer) technique
Shows how to eliminate special cases in linked list operations
Extends the concept to insertion with insert_before()
Includes compilable C code examples and illustrative diagrams
Covers Linus Torvalds' coding philosophy on good taste

Pros & Cons

Pros
  • Clearly explains a non-trivial pointer technique with concrete code
  • Provides both the naive and elegant solutions for comparison
  • Extends removal technique to insertion, demonstrating generality
  • Includes visual diagrams to aid understanding
  • Open source, free to access and use
Cons
  • Limited to singly linked lists; does not cover doubly linked lists
  • Only addresses removal and insertion operations
  • Not a full library; purely educational example code
  • Assumes familiarity with C pointers and linked list basics

Best For

Learning advanced linked list manipulation techniquesUnderstanding pointer-to-pointer patterns in CEducational resource for data structures and algorithms coursesStudying coding elegance and removal of special casesReference for implementing singly linked list operations

FAQ

What is the main point of Linus Torvalds' linked list example?
Linus demonstrates that by using a pointer-to-pointer (indirect addressing) approach, you can avoid a special case when removing an item from a singly linked list, which he considers good taste in coding.
How does the elegant solution avoid the if statement?
Instead of tracking both current and previous pointers, the elegant solution uses a pointer to the next pointer (indirect pointer). This allows uniform handling of the head node and other nodes, eliminating the need to check if the target is the first item.
Does the repository cover more than just removal?
Yes, it extends the indirect addressing technique to insertion operations, specifically implementing insert_before() for inserting a new item before an existing target.