ISSUE 6Hey Reader, We're switching things up a little bit this week. Instead of the usual Did I say blog? That's right, there is a blog now! It has exactly one article at the moment, but expect to find more in the upcoming weeks. So today, you're getting both a shorter email and more content. That's a pretty good deal, isn't it? This format might become more common as I start posting longer-form articles on the blog, so please let me know what you think about it :) This week, we'll talk about refactoring, islands architecture, component libraries, and a book about functional programming that doesn't require a Ph.D. in math. Let's do this! SOFTWARE DESIGNRefactoring with the Squint TestImagine you're trying to make a change to your codebase. Something simple, like adding a new item to a dropdown menu or a couple of new fields to an existing form. Easy-peasy. You're not too familiar with this part of the codebase, so you look around for where this component is getting its items from. When you finally find it, one of two things could happen: It could be that the change is actually as easy as you thought it would be. Maybe all you have to do is add a new item to a pre-existing array, copy and paste a unit test, and take the rest of the day off. If the change is really that easy, it's usually a sign that this particular piece of code is using the right abstraction. Or it could be that the change is not easy at all. In fact, you might come across a piece of code so messy and fragile that you fear looking at it too closely could bring the entire app down. More often than you'd like, this is what you'll find, and it's a clear indication that the code could use some refactoring. Refactoring is a broad topic, and there's typically a lot of ceremony around it. But today, I want to talk about none of that. Today, I want to talk about a refactoring method that you can use every day right after you finish writing a piece of code—what Sandi Metz calls the squint test. Here's how to do it: squint your eyes, take a step back, and look at the code. The goal of the squint test is to lose focus on the actual code and look for two things—changes in shape, and changes in color. Changes in shape mean nested conditionals or loops, which will always be hard to reason about. Changes in color (typically represented by magic strings and magic numbers) mean the code is dealing with different levels of abstraction, so the story it tells is going to be hard to follow. In her talk All the Little Things, Sandi shows an example of the squint test in action on the popular refactoring kata The Gilded Rose. This is one of my favorite programming talks of all time and a true refactoring masterclass in only 38 minutes. Definitely give it a watch right after you finish reading your favorite newsletter. The squint test doesn't tell us how to refactor a piece of code, but it's useful for identifying code that could benefit from changing. It's also the easiest way to make sure your abstractions follow the Single-Responsibility Principle. It's not a bulletproof scientific method (in case the name of the test didn't give that away), but it's a pretty good rule of thumb. So, next time you finish writing a class or function, take a few seconds to squint your eyes and lean back on your chair. If your code fails the squint test, it could mean that you're dealing with the wrong abstraction or that your function might be hard for others to understand—even if it makes complete sense to you. FROM THE BLOG 📝Sharing State with Islands ArchitectureIslands Architecture is one of my favorite rendering patterns for building websites today. It's performant, scales really well, and reminds me of my lifelong dream: move to Hawaii and eat nothing but Loco Moco and Malasadas for the rest of my days (which won't be too many with that diet.) But Islands Architecture comes with a tradeoff: communicating between interactive components is not as straightforward as in other rendering patterns. Thankfully, there are several ways to solve this challenge, and I talk about some of the most popular ones in this week's blog post.
WATCH LISTCreating Reusable Components… That Are Actually ReusableCory House gave a great talk at React Rally 2023, sharing his learnings on building reusable component libraries—which is much harder than it might seem on the surface. Not only are there lots of tiny decisions you have to make when creating a component library (50 of them, according to Cory), but even if you make all the right ones, there’s a chance your team might decide not to use it for a number of reasons. Some of the most common reasons you'll hear are that components are too bloated (they do too much), or too restrictive (they don’t do enough), or they don’t match a particular app’s style. To prevent this, Cory shares the seven keys for successful component libraries. You should definitely watch the talk to learn more about them, but here’s a sneak peak of my favorite ones:
ARCHITECTURE SNACKSLinks Worth Checking OutBOOKSHELFGrokking SimplicityBefore finding Grokking Simplicty by Eric Normand, all of my previous attempts at learning about functional programming (FP) failed miserably. Things usually started well, but as soon as the academic jargon and the code examples in Haskell showed up, my brain would immediately shut down. Thankfully, this book is different. Unlike many other functional programming books, Grokking Simplicity puts the mathematical concepts of FP to the side to focus entirely on managing software complexity. In particular, it explains how we can build better software by adopting two of the main ideas in functional thinking:
There is a lot I love about this book. For starters, it’s a practical book for software engineers, which isn’t the norm for functional programming literature. The book is also really easy to digest, thanks to the many illustrations and annotated code examples that make the content easy to follow. And, as a bonus for frontend engineers, the code samples are entirely written in JavaScript—so nothing will get lost in translation. If you're looking for a gentle introduction to FP, or want to learn new techniques for managing complexity in your applications, I highly recommend you check this one out.
|
113 Cherry St #92768, Seattle, WA 98104-2205 |
Get the latest articles, talks, case studies, and insights from the world of software design and architecture—tailored specifically to frontend engineers. Delivered right to your inbox every two weeks.
Read it on the website ISSUE 10 Hey Reader, I have some exciting news to share before we start—Frontend at Scale has officially reached 1,000 subscribers 🎉 This is absolutely incredible to me, and I cannot thank you enough for being part of this journey so far. Whether you’ve been reading my ramblings from the very beginning or you just joined us last week, I want you to know how much I appreciate you hanging out with me every two weeks. If you enjoy the newsletter, the absolutely best way to...
Read it on the website ISSUE 9 Hey Reader, I hope you had a fantastic week. Mine was great—I took some time off work to enjoy the beautiful California woods with my wife and kids, which was a much needed rest but also the reason there was no Frontend at Scale last weekend. I hope you didn't miss the newsletter too much 😊 Today I'm flying out to NYC for this year's React Summit US. I'm super excited to hang out with the nice folks from the React community and to give my talk, The Messy Middle,...
Read it on the website ISSUE 8 Hey Reader, Do you have plans for this upcoming Friday, October 27th, at 9:30am Pacific? Work, you said? I'm not entirely sure what that word means, but I hope you can make some time come chat about application design in Astro with Ben Holmes and me on my Twitch channel. This is the first of what I'm hoping will become a series of talks on frontend architecture and software design with different framework authors and experts, and I couldn't be more excited to...