130: David Khourshid - Building Better UI Components with State Machines
Episode
54 min
Read time
2 min
Topics
Leadership, Design & UX, Software Development
AI-Generated Summary
Key Takeaways
- ✓State representation: Replace boolean variables like isLoading with single status strings (idle, loading, success) to prevent impossible state combinations. Multiple booleans create 2^n possible states when only 5-7 are valid, causing bugs like Reddit showing "no results" while displaying results.
- ✓Event-driven architecture: Event handlers should only send events (like formSubmitted), not execute logic directly. The state machine determines valid transitions based on current state first, then event type, automatically ignoring invalid actions without if-statement guards protecting edge cases.
- ✓Transition structure: Implement state machines using nested switch statements that check current state first, then event type second. This inverts typical logic where actions check state, instead making states determine which actions are allowed, eliminating manual edge case handling.
- ✓Naming conventions: Name events in past tense describing what occurred (usernameChanged, dogRequested) rather than imperative commands (updateUsername, fetchData). This acknowledges events may not succeed and separates user intent from actual state changes, preventing misleading action names when operations fail.
What It Covers
David Khourshid explains how finite state machines eliminate impossible UI states by using labeled states instead of boolean flags, preventing bugs like simultaneous loading spinners and displayed data through deterministic state transitions.
Key Questions Answered
- •State representation: Replace boolean variables like isLoading with single status strings (idle, loading, success) to prevent impossible state combinations. Multiple booleans create 2^n possible states when only 5-7 are valid, causing bugs like Reddit showing "no results" while displaying results.
- •Event-driven architecture: Event handlers should only send events (like formSubmitted), not execute logic directly. The state machine determines valid transitions based on current state first, then event type, automatically ignoring invalid actions without if-statement guards protecting edge cases.
- •Transition structure: Implement state machines using nested switch statements that check current state first, then event type second. This inverts typical logic where actions check state, instead making states determine which actions are allowed, eliminating manual edge case handling.
- •Naming conventions: Name events in past tense describing what occurred (usernameChanged, dogRequested) rather than imperative commands (updateUsername, fetchData). This acknowledges events may not succeed and separates user intent from actual state changes, preventing misleading action names when operations fail.
Notable Moment
Khourshid reveals users frequently encounter stuck UI states but never report bugs because they simply restart the application instead of filing reports, meaning developers remain unaware of state machine defects that visual diagrams would immediately expose.
Episode Transcript
In this episode of Fullstack Radio, I talked to David Khorshid about how state machines can help you write simpler, more resilient UI components. This is Fullstack Radio episode 130. Hey, everyone. Welcome to another episode of the Full Stack Radio podcast. I'm your host, Adam Wadden. And today, it's my pleasure to be speaking with David Khorshid, otherwise known as David k Piano, otherwise known as the State Machine Guy. How's it going, man? Great. Yeah. Great to meet you, Adam. Yeah. You too. Thanks so much for coming on the show. I I read an article that you posted a couple of weeks back on, dev.2 or dev.to, I don't know how people say it out loud, called no disabling a button is not app logic and I thought it was really great because it really opened my eyes to some ways of thinking about how we can sort of implement, you know, pretty pretty common basic stuff that we do in user interfaces all the time in sort of a more resilient way using some ideas that I've I've sort of typically relegated to sort of theory, you know what I mean? And not leveraged too much in real world, applications. So I thought if it's cool with you, it'd be cool to talk about some of that stuff sort of from first principles working our way to some more advanced concepts and, you know, see what sort of interesting stuff we can cover. Yeah. Absolutely. So I think probably the best place to start would be, just with the idea of state machines in general. Like I kinda said before, to me, a state machine is like, yeah, I learned about that in university in computer science class and then kinda quickly forgot about it and just went off building, you know, real things, not thinking that that was something that I would have to use day to day. And to this day, you know, it hasn't been something that I've bumped into day to day, but reading this article and seeing some of the stuff that you talk about, it's making me realize, you know what? Like, this seems like a really powerful idea that can be leveraged in much simpler ways than maybe it sounds like at the outset. So how do you sort of like define the idea of state machines or introduce that to people usually? Well, it's funny you say that because there's been many people who have asked me, like, hey, I've learned about state machines in university. And it was usually around topics such as regular expressions or Turing machines or basically how computers and circuits work and all the things that don't really apply to what we do every day in web developments. But, if you look at state machines and you like Google them, look them up on Wikipedia, you're going to get a lot of confusing information. And they're really a lot simpler than it sounds. …
Get the full transcript (10,086 words) + summary by email — free
One-time email with the complete transcript and AI summary of this episode. No account needed.
One email, no spam. We’ll also show you what SignalCast does.
You just read a 3-minute summary of a 51-minute episode.
Get Full Stack Radio summarized like this every Monday — plus up to 2 more podcasts, free.
Pick Your Podcasts — FreeKeep Reading
More from Full Stack Radio
153: DHH – Omarchy and Designing Your Own OS on Arch Linux
Aug 21 · 76 min
The Jordan Harbinger Show
1321: David Royce | The Blue-Collar Advantage in the AI Era (Bonus)
May 4
More from Full Stack Radio
152: Ben Orenstein - How to Stand Out When Applying for a Job at a Small Company
Jan 28 · 47 min
Huberman Lab
Essentials: The Biology of Aggression, Mating & Arousal | Dr. David Anderson
Apr 9
More from Full Stack Radio
We summarize every new episode. Want them in your inbox?
153: DHH – Omarchy and Designing Your Own OS on Arch Linux
152: Ben Orenstein - How to Stand Out When Applying for a Job at a Small Company
151: DHH – Building HEY with Hotwire
150: Secret Screencasting Tips & Behind the Scenes of Tailwind CSS 2.0
149: Choosing a Payment Processor, Radical Icons & W3C Hype
Similar Episodes
Related episodes from other podcasts
The Jordan Harbinger Show
May 4
1321: David Royce | The Blue-Collar Advantage in the AI Era (Bonus)
Huberman Lab
Apr 9
Essentials: The Biology of Aggression, Mating & Arousal | Dr. David Anderson
My First Million
Mar 13
This guy names billion dollar brands for a living, here’s his exact 3-step formula.
Huberman Lab
Nov 27
Essentials: Using Hypnosis to Enhance Mental & Physical Health & Performance | Dr. David Spiegel
The Joe Rogan Experience
Aug 7
#2537 - David Sinclair
Explore Related Topics
This podcast is featured in Best Cybersecurity Podcasts (2026) — ranked and reviewed with AI summaries.
Read this week's Software Engineering Podcast Insights — cross-podcast analysis updated weekly.
You're clearly into Full Stack Radio.
Every Monday, we deliver AI summaries of the latest episodes from Full Stack Radio and 192+ other podcasts. Free for one show.
Start My Monday DigestNo credit card · Unsubscribe anytime