One of the most significant benefits of understanding a programming language is that you can get **extremely concrete** explanations of how things work. # Example: Fibonacci Here's the Fibonacci function in math notation: $ F(n) = \begin{cases} 0, & \text{if } n = 0, \\ 1, & \text{if } n = 1, \\ F(n - 1) + F(n - 2), & \text{if } n > 1 \end{cases} $ To me, mathematical notation never quite clicked. I'm sure with reps it would become natural, but I find it impenetrable by default. Now, here's the _exact same idea_ in code (JavaScript): ```js function fib(n) { if (n === 0) return 0; if (n === 1) return 1; return fib(n - 1) + fib(n - 2); } ``` Such clarity! ## Example: Summation The summation syntax in math has always been particularly unintuitive in my opinion. Here's the sum of all integers 1-n. In other words: `1 + 2 + 3 + ... + n`. $ S = \sum_{i=1}^{n} i = \frac{n(n + 1)}{2} $ Oof, that looks abstract. How about this: ```js function sumToN(n) {   let total = 0;   for (let i = 1; i <= n; i++) {     total += i;   }   return total; } ``` So concrete! The math notation is also saying that this can be done in a single constant-time operation: ```js function sumToN(n) {   return n * (n + 1) / 2; } ``` Again, this is fully concrete and immediately understandable if you understand code. ## Example: Consistent Hashing Here's a longer example. There's a concept called consistent hashing. The core idea is that if you assign an arbitrary key to `1` of `n` nodes you want to be able to add or remove nodes without re-mapping the majority of keys. Consistent hashing is often described visually: ![[CleanShot 2025-10-12 at [email protected]]] This is indeed quite helpful for understanding both the "what" and the "how" of consistent hashing. However, it still lacks a fundamental _concreteness_. If you hand me a request and ask "which node should I send this to" what should I do? Trace my finger along the diagram and tell you the answer? That clearly won't work in a real system, but what will? This is where code comes in. The combination of a visual explanation **AND** a code sample makes everything clear. > [!NOTE]- Expand to see a Python implementation > ```python > import hashlib > from bisect import bisect_right > > class ConsistentHashRing: > def __init__(self, nodes, virtual_nodes=150): > self.nodes = nodes > self.virtual_nodes = virtual_nodes > self.ring = {} > self._build_ring() > > def _build_ring(self): > for node in self.nodes: > for i in range(self.virtual_nodes): > key = hashlib.md5(f"{node}:{i}".encode()).hexdigest() > self.ring[int(key, 16)] = node > self.sorted_keys = sorted(self.ring.keys()) > > def get_node(self, key): > """Map key to node""" > hash_key = int(hashlib.md5(key.encode()).hexdigest(), 16) > idx = bisect_right(self.sorted_keys, hash_key) > if idx == len(self.sorted_keys): > idx = 0 > return self.ring[self.sorted_keys[idx]] > > def add_node(self, new_node): > """Adding node only remaps ~1/N keys""" > self.nodes.append(new_node) > for i in range(self.virtual_nodes): > key = hashlib.md5(f"{new_node}:{i}".encode()).hexdigest() > self.ring[int(key, 16)] = new_node > self.sorted_keys = sorted(self.ring.keys()) > > ring = ConsistentHashRing(['shard-0', 'shard-1', 'shard-2', 'shard-3']) > shard = ring.get_node('org-microsoft') # => shard-2 > ring.add_node('shard-4') # add new shard, only ~25% of orgs move > ``` Before I knew code, this would have looked like gibberish. However, being able to trace this logic makes everything clear. Moreover, you can improve clarity by typing out the code. ## A hierarchy of clarity 0. Verbal or written explanation. 1. Visual explanation. 2. Read the code. 3. _Write_ the code. This is very powerful. Being able to read and write code is a superpower for understanding abstract concepts (math, logic, etc). This is your bandwidth for understanding. How quickly can you assimilate knowledge? Code is a shortcut. It's a common language between computer and human, and moreover its a language LLMs speak very well. I find this particularly powerful because so many of my questions for LLM boil down to "How does $X work?" `X` could be anything, like "consistent hashing", "healthcare", "the economy", etc. Not every problem lends itself to a technical explanation, but whenever discussing a technical topic its extremely powerful to simply say to the LLM "show me the code". ## Not perfect, but better Code, concrete as it may be, is also not perfect. - The code could have a bug, which can be _very hard_ to identify simply by reading it. - Any code involving async operations can have a race condition, which can be hard to identify even at runtime. - It's entirely possible to misunderstand a piece of code, even if the code itself is 100% functional. Despite the drawbacks, it's still a massive improvement when trying to reason about abstract notions.