Programming
How one language or tool really behaves: the mechanism, a snippet that runs, and where it breaks.
GoByte Skills: 9 tracks. One mechanism, one snippet, one animation.
See the seriesLatest in Programming
RSS-
GSAP timelines: animation as data
GoByte Skills #19: a GSAP timeline is a seekable program. Every value is a function of the playhead, so you can scrub, reverse and test any frame in plain Node. Plus the three ways it quietly stops being pure.
-
this: decided at the call site
GoByte Skills #18: this is decided at the call site, not where the function is written. One function, three calls, three answers, and why arrows opt out.
-
Closures: functions remember where they were born
GoByte Skills #17: A closure captures the variable, not the value. That is why three callbacks in a var loop all print 3 and the let loop prints 0, 1, 2.
-
The event loop: await does not block
GoByte Skills #16: await suspends one function, not the thread. Six log lines, two queues, one fixed order, and why a setTimeout of 0 still waits for every microtask.
-
Make illegal states unrepresentable
GoByte Skills #15: Three booleans are 8 states and your screen means three. Model React state as a tagged union and the compiler rules out the other 5. Validate the data at the edge, and the inside stays honest.
-
State is a snapshot
GoByte Skills #14: In React, count is not a live variable. Each render gets its own constant, and a click handler only ever sees the render it was born in. That is why setCount(count + 1) three times adds one, and how the updater fixes it.
-
TypeScript narrowing: typeof is the bouncer
GoByte Skills #13: typeof does not just check a type, it proves one. After the check each branch gets a narrower type and the compiler holds you to it. A handwritten type guard only promises.
-
The borrow checker: many readers or one writer
GoByte Skills #12: Rust lets you hold many shared references or one mutable one, never both. That single rule is why push on a borrowed Vec does not compile, and why two threads cannot write the same variable without a lock or an atomic.
-
Ownership: one owner, no garbage collector
GoByte Skills #11: Rust frees memory without a garbage collector because every value has exactly one owner. Move it and the old name is dead. When the owner's scope ends, the compiler has already written the drop call.
-
The ? operator: errors are values
GoByte Skills #10: The ? operator is a match you did not have to type. On Err it converts the error through From and returns early, so the error changes type on the way up and never leaves the signature. No exceptions, no unwinding.
-
Mutable defaults: evaluated once
GoByte Skills #9: A default argument is evaluated when def runs, not on each call, and stored on the function. So a list default is one list that every call shares. Why, the None fix, and why += is the same bug in disguise.
-
The GIL: threads for waiting, processes for work
GoByte Skills #8: The GIL lets one thread run Python bytecode at a time. Four threads on CPU work finish no faster than one. Four processes really run in parallel. Measured, plus why the __main__ guard is not style.