From source to instructions

A translator walks your text down to instructions, one form at a time

Source textjust bytes in a filex = 1 + 2Tokenslex: split into wordsx=1+2Treeparse: what belongs to what=x+12Middle form (IR)check types, simplifyt1 = add 1, 2store x, t1optimiser folds 1 + 2store x, 3Machine codeemit for one chipmov [x], 3one x86 instructionEvery language lowers to a shared middle form, so the hard parts are built onceCC++RustSwiftLLVM IRx86ArmRISC-VWasmFour languages and four chips need 4 + 4 pieces, not 16. A new chip gets every language for free.The optimiser works on this form: the same source built with -O2 instead of -O0 typically runs 2 – 10× faster.

A program is text until a compiler or interpreter lowers it: tokens, a tree, a shared middle form, then machine code.

From source to instructions · Going deeper · 1 of 2

The compiler front-end pipeline, with `x = 1 + 2` shown at each stage Source text x = 1 + 2; lexer Tokens IDENT('x') · '=' · INT(1) · '+' · INT(2) · ';' parser AST (parse tree) = x + 1 2 semantic analyzer Typed AST x: i32 ← (1: i32) + (2: i32) lowering Intermediate representation (IR) %t1 = add i32 1, 2 store i32 %t1, i32* %x front end → to back end

The front-end pipeline

Lexing, parsing, type checking and lowering to an intermediate representation are the same in compilers, interpreters and editor tooling: linters and language servers reuse the front end. LLVM IR, GCC’s GIMPLE and JVM bytecode all play the role of the shared form.

From source to instructions · Going deeper · 2 of 2

Compiler middle and back end — IR through optimization passes to machine code IR (from front end) %t1 = add i32 1, 2 · store %t1 → %x Middle end · optimization passes (each: IR in → IR out) constant fold dead-code elim inlining loop unroll add 1, 2 ↓ i32 3 if (false) {…} ↓ (removed) call sq(x) ↓ x * x for i in 0..4 ↓ a;b;c;d CSE / GVN SROA · mem2reg · vectorize find equal subexpressions, compute once (common-subexpression / global value numbering) promote stack slots to registers, SIMD-ify inner loops where possible Back end · target-specific lowering instruction selection register allocation machine code map IR ops → x86/ARM graph colouring · spills .text section bytes passes are sequenced · each one is a tree rewrite · LLVM ships ≥ 100 of them, run at -O2 in a fixed pipeline

Optimising, then picking instructions

The middle end is a chain of passes, each taking the middle form and returning a better one: constant folding, dead-code removal, inlining, loop transforms. The back end then selects instructions and decides which values get one of the 16 registers on x86-64. A spill to the stack inside a hot loop can erase every other gain.

Compiled, interpreted, JIT

Compiled, interpreted, JIT: the same translation at different times

before the program runswhile it runscost per operationyou press runAhead of timeC, C++, Rust, Gotranslate the whole programinto native code, oncethe CPU runs it directly1×the baselineInterpretedBash, Ruby, classic Pythonnothing: it starts instantlytranslate each step as it runs,again every single time10 – 100×slowerBytecode + JITJava, C#, JavaScriptcompile toportable bytecodeinterpretrecompile hot partsto native codenear 1×once warmed uptranslation workAll three do the same translation. They differ only in when.Earlier means faster running. Later means instant start, code you can change live, and one file that runs on any machine.

Translate ahead of time for speed, interpret for instant start, or ship bytecode and compile the hot parts while running.

Compiled, interpreted, JIT · Going deeper · 1 of 3

AOT compilation, interpretation, and bytecode-VM-with-JIT — three contracts for getting bytes to run AOT compilation Interpretation Bytecode + VM (+ JIT) C · Rust · Go Bash · classic CPython Java · JS · modern Python main.c compile main.o link → ELF CPU runs native all-or-nothing translation deploy = ship a binary main.py read parse eval repeat CPU runs interpreter loop walk source per execution deploy = ship the source Foo.java javac Foo.class (bytecode) JVM interp + JIT CPU runs native (hot) portable bytecode + runtime deploy = ship bytecode + VM no path is "best" — they trade startup time, peak speed, deploy footprint, and platform reach

Three contracts, side by side

The boundaries blur in practice. Go compiles ahead of time but ships a runtime for its lightweight threads and garbage collector. Python caches bytecode in __pycache__ but still interprets it. The JavaScript engine in Chrome has four compiler tiers.

Compiled, interpreted, JIT · Going deeper · 2 of 3

Linker resolves symbols across object files and libraries into one executable main.o math.o libc.a DEFINES: main UNDEF: square UNDEF: printf DEFINES: square DEFINES: cube UNDEF: pow DEFINES: printf, pow, … linker build symbol table resolve UNDEF → DEF apply relocations lay out sections a.out (ELF) main: 0x401000 square: 0x401080 cube: 0x4010c0 printf: 0x401200 pow: 0x4012a0 static linking: copy symbols in at build time · dynamic linking: leave a stub, resolve at load time

Linking: joining the pieces

Each source file compiles alone into an object file with holes where other files’ functions go. The linker builds one table of who defines what, then patches every hole with a final address. “Undefined reference” means no file defined it. Static linking copies library code in; dynamic linking lets the system patch it at start-up, so one copy of a library serves every program.

Compiled, interpreted, JIT · Going deeper · 3 of 3

A function call's stack frame layout, with x86-64 SysV register passing high addresses low addresses · stack grows down caller's frame main()'s locals, saved regs return address (push by CALL) saved frame pointer (old rbp) callee-saved regs callee's locals int x · char buf[16] · … addressed off rbp as [rbp-N] rsp points here ← top of stack x86-64 SysV registers arg 1 → rdi arg 2 → rsi arg 3 → rdx arg 4 → rcx arg 5 → r8 arg 6 → r9 arg 7+ → on stack return → rax caller-saved: rax · rcx · rdx · rsi rdi · r8-r11 callee-saved: rbx · rbp · r12-r15 grows CALL pushes return addr · prologue saves rbp · epilogue + RET unwinds it

Function calls and the stack frame

Every call pushes a frame: the return address, saved registers and local variables. A calling convention fixes where arguments travel; on 64-bit Linux and macOS the first six go in registers. Writing past a local buffer can overwrite the return address, which is “smashing the stack”; a random canary checked on return is the standard guard.

How a JIT works

A JIT starts slow, watches the program, then bets on what it saw

speed of one function, compared with the interpreter1×20×100×call 1call 1,000call 10,000a string arrivesinterpretercounts calls, notes typesquick native codefor float arrays, plus a guardoptimised native codeinlined, tuned to what it sawguard fails:back to theinterpreterThe betif a is not float[]:    deoptimise()It watched 1,000 calls andsaw only float arrays, so itcompiled for exactly that.A compiler working aheadof time can only guess.The first calls are slower than plain interpreting; the millionth is close to compiled code.A benchmark that runs for 100 ms never leaves the slow tier, and reports misleading numbers.

A JIT compiles only hot code, specialised to the types it observed, and falls back when the bet fails.

How a JIT works · Going deeper

JIT tier-up and de-optimization Bytecode Profiler Native (optimized) interpreted ≈1× start cost counts calls + types "hot" when ≥ N specialized to observed types execute tier up · compile de-optimize: assumption violated → fall back to interpreter Most code rarely runs. JITs spend their optimization budget only on the few percent of methods that get hot, and stay safe by guarding every assumption with a runtime check.

Tier-up and de-optimisation

Thresholds are around 1,000 calls for a baseline tier and 10,000 for an optimising one. A JIT can be bolder than an ahead-of-time compiler because it sees real behaviour: a branch never taken is left out of the fast path. Start-up pays for both interpreting and profiling, which is why short benchmarks need a warm-up.

Check yourself

14001,000calls →the benchmarkcompiles to native here

A benchmark calls a function 400 times on a runtime that compiles hot code after 1,000 calls, and reports it as slow. What did it measure?

Language design choices

Every language is four choices, and what it refuses is its character

Control or safety?raw memory, no checksevery access checkedCRustGo, JavaPythonFast to run or to write?fastestfewest linesPython is typically 10 – 50× slower than CCRustGo, JavaPythonTypes checked when?before it runswhile it runsCRustGo, JavaPythonWho frees memory?youthe runtimeCRust: the compilerGo, JavaPythonThe four choices are independent.Rust is as fast and low-level as C, yet nearly as safe as Python: it moved the checks into the compiler.

Control or safety, speed or expressiveness, static or dynamic types, manual or managed memory: four independent positions.

Language design choices · Going deeper

The four orthogonal trade-offs every language picks Control Safety low-level high-level Speed Expressiveness close to metal close to math C · asm Python asm · C Haskell · Lisp Static typing Dynamic typing checked deferred Manual memory Managed memory free() GC · ownership Rust · OCaml Lisp · JS C · C++ Java · Go · Rust orthogonal axes · every language picks a coordinate · Rust sits at (control, speed, static, managed)

The four axes as a grid

C exposes undefined behaviour: use an address that is not yours and anything may happen. Python and JavaScript hide raw pointers and bounds-check every access. Rust keeps pointers but tracks them at compile time, and fences the unchecked operations inside explicit unsafe blocks.

Static and dynamic typing

Static typing catches the mistake at build time; dynamic typing meets it in production

count = 5count.length    # a number has no lengthEvery language agrees this is a mistake.They differ on when you find out.you write itbuildtestsa user runs itStatic: Java, Go, Rustcaught: the compiler refuses to buildDynamic: Python, JavaScriptcrashes here, unless a test happened to run that lineGradual: TypeScript, mypythe parts you annotatedeverything else still fails lateStatic typing moves a whole class of failures from your users to your editor.The price is effort up front; dynamic languages let the first version come faster.

A type checker moves a class of failures from the moment a user runs the line to the moment you build.

Static and dynamic typing · Going deeper

When type errors are caught — across the program lifecycle edit compile link / load run never "red squiggle" type-check pass JVM bytecode verifier TypeError thrown silent wrong answer Rust · OCaml · Haskell · TypeScript (strict) Java · C# · Go (compile + load-time bytecode verify) Python · Ruby · plain JS earlier ← → later when does the type system catch the bug?

Across the program’s lifetime

Gradual typing, such as TypeScript or Python with mypy, lets a project move checks earlier without a rewrite. The catch: types are enforced only where you annotated. Modern checkers also narrow as the code branches: a value that is “string or null” becomes plain string inside an if that rules null out.

Memory management

Someone must free memory: you, the runtime, or the compiler

one piece of memory, over time →You free itC, C++in usefreed, but still pointed atforget to free: a leak · use it afterwards: someone else’s data · free it twice: corrupted bookkeepingprice: three classic bugsbehind many C and C++ security holesThe runtime frees itJava, Go, Python, JavaScriptin useunreachable, waitingcollecteda garbage collector finds what nothing points at any more, and frees it for youprice: pausesa few milliseconds on modern collectorsThe compiler frees itRustin use by its one owner}owner’s scope ends: freed at onceevery value has exactly one owner; the compiler inserts the free where that owner endsprice: a stricter compilercode will not build until ownership is clearOne problem, solved at three different moments: by you, by the running program, or by the compiler.Garbage collection trades some speed for safety. Ownership keeps both, and charges you while compiling instead.

Manual freeing risks three classic bugs, a garbage collector costs pauses, and ownership moves the work into the compiler.

Memory management · Going deeper · 1 of 2

Manual, garbage-collected, and ownership-based memory management Manual Garbage collection Ownership C · C++ Java · Go · Python · JS Rust malloc free use programmer balances every alloc + deterministic destruction + zero runtime cost − leaks · use-after-free · double-free − entire bug class is a CVE source new use forget GC pause runtime sweeps unreachable objects + no use-after-free / double-free + "just allocate, forget about it" − pauses (μs to ms; tunable) − 1.5–4× memory overhead is typical let x = … use scope end compiler inserts drop at scope end + deterministic · no GC · no UAF + aliasing rules block data races − steeper learning curve − "fight the borrow checker" three points on the same axis: deterministic + cheap + safe — pick two, or shape your program around the third reference counting (Swift, Python's primary mechanism) is a fourth flavour — deterministic but bad with cycles

Three strategies compared

Manual management, tracing collection and ownership solve the same problem at different points in the lifecycle. Concurrent collectors such as Go’s and Java’s ZGC keep the stop-the-world part to single-digit milliseconds even on heaps of hundreds of gigabytes. Rust gets no pause at all but rejects programs whose lifetimes it cannot prove.

Memory management · Going deeper · 2 of 2

Generational GC — small frequent young-gen collections, rare expensive old-gen collections Young generation Old (tenured) generation small · collected often (ms) large · collected rarely (seconds–minutes) survived N promote Object lifetime histogram (the generational hypothesis) ≥ 95% die here (young) few % live long (old) very few live forever

Most objects die young

Across decades of measurements, most allocations become unreachable shortly after they are made. A generational collector keeps a small young area, typically 5 – 10% of the heap, collected often and cheaply, and promotes survivors to an old area collected rarely.

Garbage collection

Garbage is whatever the program can no longer reach

Rootsthe call stack,registers, globals1 start hereABCD2 follow every pointer, mark what you reachEFG3 nothing reaches these, so they are freedTracing collectionUsed by Java, Go and JavaScript.The work follows what is alive,not what is dead.Counting references insteadSwift and Python free an object themoment its count reaches zero: nopause. But E and F point at eachother, so both stay at 1 forever.Most objects die youngSo collectors check the newest5 – 10% of memory often, and therest rarely. Pauses stay small.Garbage means unreachable: if no chain of pointers from a root leads to it, no code can ever use it again.

A tracing collector marks everything reachable from the roots and frees the rest. Counting references is simpler but leaks cycles.

Garbage collection · Going deeper · 1 of 2

Mark-and-sweep — DFS from roots marks live objects, sweep frees the rest Mark phase Sweep phase root root A B C D E F unreachable unreachable heap (after sweep) A B D C E F filled = live (kept) dashed = unmarked (freed) cost: O(live) mark + O(heap) sweep stop-the-world unless concurrent fragmentation accumulates over time concurrent collectors keep the program running during mark, using a tri-colour invariant to track work

Mark and sweep

Marking is a graph traversal from the roots; sweeping is a linear walk of the heap. Marking costs in proportion to live data, sweeping in proportion to the whole heap. Compacting collectors add a third phase that moves live objects together to defeat fragmentation.

Garbage collection · Going deeper · 2 of 2

Reference counting cycle — two objects keep each other alive after external refs drop Step 1 · external ref + cycle Step 2 · external ref dropped user A B rc=2 rc=1 user → A · A ↔ B user (gone) A B rc=1 rc=1 A.rc=1 · B.rc=1 · neither hits 0 leak — unreachable but undeletable Fix: weak references break the cycle A holds a strong ref to B; B holds a *weak* ref to A. Weak refs don't bump the count. When user drops A, A.rc → 0 · A frees · A's strong ref to B drops · B.rc → 0 · B frees.

Reference counting and cycles

Swift, Python and C++ shared pointers count references. To break cycles they offer a weak reference that does not raise the count, and Python also runs a periodic tracing collector for cycles the programmer forgot.

Check yourself

RootsABCD

Nothing else points at C or D. Which kind of collector can free them?

Programming paradigms

Four ways to organise the same computation

Imperativedo these steps, in this ordertotal = 0for i in 1..n:    total += i * iObject-orientedask the thing that owns the dataclass Range:    def sum_squares(self): ...Range(1, n).sum_squares()Functionalchain transformations, change nothingrange(1, n)    .map(i => i * i)    .sum()Declarativedescribe the result, not the stepsSELECT SUM(i * i)FROM numbersWHERE i <= nOne task, 1² + 2² + … + n², in four ways of thinking.Real programs mix them: imperative for input and output, objects for the domain, functions for transformations, SQL for queries.

A paradigm is a default shape for code: commands, objects, transformations, or a description of the result.

Programming paradigms · Going deeper · 1 of 3

Same task — sum of squares 1..n — in four paradigms Imperative Object-oriented Functional Declarative "do these steps in order" "send messages to objects" "compose pure transformations" "describe the result, not the path" total = 0 for i in 1..=n: total += i * i return total class Range: def sum_sq(self): return sum( i*i for i in self) (1..=n) .map(|i| i*i) .sum() SELECT SUM(i*i) FROM generate_series( 1, n) AS s(i);

The same task in four paradigms

Modern languages mix all four, and the choice is per module rather than per language: imperative input and output, an object-oriented domain model, functional transformations, embedded SQL for queries.

Programming paradigms · Going deeper · 2 of 3

A closure — function value carries its captured environment source function make_counter() { let count = 0; return () => ++count; } use let next = make_counter(); next(); next(); next(); // 1 2 3 closure value at runtime code ptr → .text: lambda body env ptr → heap: { count: 3 } (one per make_counter call; captured by reference) a closure = code pointer + environment record two closures from two calls share *no* state "upvalues" in Lua, "free variables" elsewhere return a function value is two pointers, not one · the second is what makes "stateful callback" a language feature

Closures: functions that remember

A closure is a function that carries the variables it was created with: a pointer to code plus a small record of captured values, kept on the heap so they outlive the call that made them. C has none, which is why C callbacks always pass an extra pointer of user data.

Programming paradigms · Going deeper · 3 of 3

Object memory layout — instance header + fields, vtable holds method pointers Dog instance (heap) header vtable ptr · type · GC bits name: "Rex" age: 5 weight: 22.0 owner: ptr → Person tags: ptr → Vec +0 +8 +16 +24 +32 +40 Dog vtable (one per class) [0] speak → Dog::speak [1] eat → Animal::eat [2] sleep → Animal::sleep [3] fetch → Dog::fetch [4] drop → Dog::drop vtable ptr obj.speak() → obj.vtable[0]() virtual dispatch = two loads + an indirect call

What an object looks like in memory

An object is a block of fields plus a hidden pointer to its class’s table of methods, the vtable. A method call is two memory loads: fetch the table, fetch the slot, then call. Go interfaces and Rust trait objects carry the table pointer beside the data instead.

Complexity and Big O

How the work grows matters more than how fast each step is

One million items, one step per nanosecond. How long does the work take?1 ns1 µs1 ms1 s17 min(each mark is 1,000× the last)O(1)hash map lookup1 stepO(log n)search a sorted list20 stepsO(n)read every item once1 millisecondO(n log n)sort them20 millisecondsO(n²)compare every pair17 minutesO(2ⁿ)try every combinationnever finishes: just 30 items already take a full second, 40 take 18 minutesBig-O names the shape of the growth, and the shape decides what is possible.Moving to a better class is usually a 1,000× win. Tuning inside a class is usually 2×.

Big-O names how work grows with input. At a million items, that shape is the difference between a millisecond and 17 minutes.

Complexity and Big O · Going deeper · 1 of 4

Big-O complexity classes — log-y scale 109 107 105 103 101 1 1 10² 10⁴ 10⁶ 10⁸ O(1) O(log n) O(n) O(n log n) O(n²) O(2ⁿ) work input size n Wall-clock at n = 10⁶ (1 ns / op) O(log n) ≈ 20 ns · O(n) ≈ 1 ms · O(n log n) ≈ 20 ms · O(n²) ≈ 17 minutes · O(2ⁿ) is heat-death-of-the-universe territory

The growth curves

O(f(n)) means that for large enough n the work grows no faster than a constant times f(n). Constants are dropped because they vary by machine. The curves show why a quadratic loop hidden in a nightly job eventually brings it down as data grows.

Complexity and Big O · Going deeper · 2 of 4

Sorting algorithms: best, average, worst, space, stability Algorithm Best Average Worst Space Stable Insertion O(n) O(n²) O(n²) O(1) yes Merge O(n log n) O(n log n) O(n log n) O(n) yes Quick O(n log n) O(n log n) O(n²) O(log n) no Heap O(n log n) O(n log n) O(n log n) O(1) no Radix O(nk) O(nk) O(nk) O(n+k) yes Timsort O(n) O(n log n) O(n log n) O(n) yes Introsort O(n log n) O(n log n) O(n log n) O(log n) no your standard library uses a hybrid · Python: Timsort · C++: introsort · Rust: pdqsort

Sorting: the classic trade-offs

No comparison sort can beat n log n on average: that is a mathematical floor. Real libraries ship hybrids: Python’s Timsort detects runs that are already sorted, and C++ uses quicksort with fallbacks. Stable means equal items keep their order, which matters when you sort by one key and then another.

Complexity and Big O · Going deeper · 3 of 4

BFS vs DFS on the same graph — visit order labeled on each node BFS · queue · level-by-level DFS · stack · depth-first 1 2 3 4 5 6 7 1 2 5 3 4 6 7 visit by level: root, then siblings, then grandchildren visit each subtree fully before its sibling both are O(V + E) · same data, different discipline · queue vs stack is the only structural difference

Graphs: breadth or depth first

Breadth-first search uses a queue and explores level by level, which finds shortest paths. Depth-first search uses a stack and follows one branch to its end, which finds cycles and orderings. The only structural difference is queue versus stack. Dijkstra’s shortest path is breadth-first with a priority queue.

Complexity and Big O · Going deeper · 4 of 4

Recursion vs iteration vs tail-call optimization — same factorial, three stack shapes Recursive Iterative Tail-recursive + TCO fact(n): if n=0: return 1 return n*fact(n-1) fact(n): acc = 1 while n > 0: acc *= n; n -= 1 return acc fact(n, acc=1): if n=0: return acc return fact(n-1, acc*n) fact(5) fact(4) fact(3) fact(2) fact(1) fact(0) fact (single frame) acc, n live in regs no calls pushed fact (frame reused) JMP, not CALL depth stays at 1 stack depth O(n) stack overflow risk past 10K stack depth O(1) always safe stack depth O(1) if compiler implements TCO tail call: recursive call is the *last* thing the function does · TCO turns the CALL into a JMP

Recursion and the stack

A recursive function adds a stack frame per call, so deep recursion can run out of stack. If the recursive call is the very last step, some compilers reuse the frame: tail-call optimisation. Scheme and OCaml guarantee it; Rust and the JVM do not.

Check yourself

4 customers8 customerstwice as many

Comparing every customer with every other takes 1 second for 1,000 customers. About how long for 100,000?

Core data structures

Four shapes hold most of the world’s data

Arrayabcde01234side by side in memory✓jump to item 3 in one step✗insert in the middle→fastest to scanHash mapBobBob → 42the key says where to look✓find by key in one step✗keeps no order→caches, lookups, countingBalanced tree50307020406080smaller left, larger right✓sorted, log n steps to find✗slower than a hash per key→database indexesQueue and stack321inoutin at one end, out at an end✓add and remove at the ends✗reach into the middle→task queues, undo, searchPick the shape by the operation you do most.Then memory layout breaks ties: scanning a 1 KB array that sits in cache beats a tree lookup that misses it, whatever Big-O says.

An array, a hash map, a tree or a queue: choose by the operation you do most often.

Core data structures · Going deeper

Operation costs across the four staple data structures Structure Access by index Search by value Insert Delete Array (dynamic) O(1) O(n) O(1)* amortized O(n) Linked list O(n) O(n) O(1) O(1) Hash map — O(1) avg O(1) avg O(1) avg Balanced tree O(log n) O(log n) O(log n) O(log n) Queue (FIFO) — — O(1) O(1) Heap (priority q) — — O(log n) O(log n) "avg" for hash map: assumes a good hash and a load factor below the rehash threshold arrays beat linked lists in practice for less than 1000 items even where Big-O suggests otherwise — cache lines win

Costs of each operation

Big-O is the floor of the conversation, but memory layout decides the wall clock. A scan of a small array that sits in cache beats a tree lookup that misses cache, even though the tree is better on paper.

Hash maps

A hash map finds a key in one step because the key computes its own address

012345678 slotshash(key) % 8a number, 0 to 7AliceAliceBobBobCarolDaveCarolDavethree keys landed in slot 7: a collision, kept as a short listHow full is it?6 of 8 slots = 0.75: grow now16 slots, every key re-placedcollisions are rare againA hash map finds any key in about one step, because the key itself computes where to look.It regrows before the lists get long. That one slow insert is repaid by all the fast ones around it: constant time on average.

Hash the key, pick a slot, store it there. Collisions become short lists, and the table doubles before they grow long.

Hash maps · Going deeper

Hash map mechanics: keys → hash → bucket, with a chained collision "Alice" "Bob" "Carol" "Dave" hash() SipHash · FNV · xxHash · CityHash ↓ mod N slot 0 slot 1 slot 2 slot 3 slot 4 slot 5 slot 6 Alice Carol collision · chained load factor = entries / slots · rehash above ≈0.75 (doubles the bucket array, re-inserts everything) average O(1); worst-case O(n) when an adversary picks colliding keys — randomize your hash seed the most-used non-trivial data structure in computing

Chaining, probing and hash flooding

Chaining keeps a small list per slot; open addressing probes neighbouring slots instead. Either way a load factor near 0.75 triggers a rehash, which is O(n) once and O(1) amortised. Attackers can choose keys that all collide, so Python, Rust and Go randomise the hash seed at start-up.

Summary

A language is a translator plus a set of refusals

Algorithms and data structuresbelong to the maths, not the language: the growth class and the shape of the data decide what is feasibleSource texta file of bytesthe CPU cannot readTranslatorlex · parse · check · IR · optimise · emitahead of time, on the fly,or bytecode + JITInstructionswhat the CPUactually runs…and four refusals that give each language its characterControl or safetySpeed or expressivenessTypes: before or duringMemory: who frees itA language = a translator + a set of refusals.Everything above it, the algorithms and the shapes of data, carries over unchanged from one language to the next.

Text becomes instructions; four choices shape the language; algorithms and data carry over to all of them. Next: distributed systems, when one machine is not enough.

Summary · Going deeper

From source text to running instructions, framed by four trade-offs Source text a file of bytes a programmer wrote Tokens · AST · IR lex · parse · semantic check · lower Native code Bytecode + VM Tree-walk AOT · gcc · rustc javac/JVM · CPython interpreter · CPython AST Running on the CPU of Act II fetch · decode · execute · repeat The four trade-offs every language picks once control ↔ safety C ↔ Python speed ↔ expressiveness asm ↔ Haskell static ↔ dynamic OCaml ↔ Lisp manual ↔ managed C ↔ Java/Rust algorithms and data structures sit above all of this — they belong to the math, not the syntax

The map of this lesson

Source text goes down one of a few paths to running instructions, and every language takes a position on four trade-offs. That choice of path and position is roughly the personality of every language you will meet.

Lesson complete

You finished “Instructions”

Answer the questions along the way to see your score here.

Open in a new tab