I realized that my previous email subscription / newsletter setup wasn’t working anymore, which is why you didn’t see any email when my last blog post came out. Sorry about that! I’ve migrated to a new setup on Buttondown, so things should go smoothly from here on out.
Like before, I’ll mostly use this list to let you know about new articles on my blog. I’m also going to experiment with some newsletter-only content — longer-form stuff than what I post on Twitter, but a bit less polished than my blog posts (and hopefully more frequent).
So, maybe some of you have seen this already 😬 but I recently published a new blog post — Three ways of handling user input:
It’s 2022 and things are pretty much the same: the dominant way of handling user input is still based on events and — in some form or another — callbacks. They come in slightly different forms (addEventListener, responder objects, etc.) but the core idea is the same.
It’s still going strong more than 40 years later, so the event-and-callback-based approach clearly has something going for it. But in nearly every code base I’ve worked in, the hairiest, most difficult-to-modify logic is in the event handling code. Handling user input is — to borrow a phrase from Laurence Tratt — a solved problem that isn’t.
To help me understand the pros and cons of the events-and-callbacks model and to experiment with some other approaches, I decided to write up a simple example in a three different styles.
After publishing the post, I actually discovered an article by Ingo Maier Martin Odersky called Deprecating the Observer Pattern which covers similar ground. If you enjoyed the blog post, their paper is worth reading as well.
Several people got in touch to tell me about bugs that they’d found, which wasn’t totally shocking. One of the points I wanted to make was that even simple drag-and-drop behaviour is surprisingly hard to get right! Here’s a bug with Figma’s implementation that took me about two minutes to find:
(The bug: I hit “Esc” to cancel the drag while the alignment guides were visible, then the guides don’t disappear on mouseup like they should.)
There’s such a huge difference between reading a paper about an algorithm/system/etc., and trying to implement it yourself.— Patrick Dubroy (@dubroy) January 23, 2022
I read the paper and think “I get it”.
I try to implement it and realize I didn’t get it at all.
Anyways, I’m planning a follow-up post where I’ll dive a bit deeper into the process-oriented model, and probably cover CML a bit. I hope to have that out in the next few weeks. 🤞
Until next time,