A stale while revalidate cache macro by Rias Van der Veken. With stale while revalidate, expired cache items will still be used when requested, but the data will be revalidated right after. That means the current request will be handled faster than if the cache would have to be revalidated, and the next request will receive fresh data.
Stale while revalidate is often used in web applications, popularized by Vercel’s SWR React library.
Technology didn’t have to glow. […] There were devices that simply did what they were for, without demanding attention.
I’ve always had a soft-spot for e-ink screens. Tom MacWright puts it better than I ever could, we should be the ones demanding attention from technology, not vice-versa.
Stefan Zweifel explains how he stores user preferences in a Laravel application using spatie/laravel-data. With the data package, you can store user settings as a blog of JSON in your database—so you don’t need to update your table schema for every change—and have a typed object to work with in code.
He mentions poor query performance as a possible tradeoff if you need to query the database for a specific value.
One thing to keep in mind is that querying for specific settings can lead to performance issues and should probably be avoided.
If your app regularly needs to query for users who have selected a particular date_format , it’s better to promote this setting to its own column. This makes the work of your database and possible indexing much easier.
If this is something you need, you could solve it with a virtual column mapped to a JSON value of the settings object. There’s a nice tutorial on that on the Kirschbaum blog
This week, I released Svelte by Example, a tutorial/resource/whatever-you- want-to-call-it introduction to Svelte.
The goal of Svelte by Example is not to turn you into an expert Svelte consultant after reading it through, but to introduce you to the framework’s main concepts, and hopefully peak your curiosity and have you dig deeper.
If you’ve been curious about Svelte but haven’t had time to give it a look yet, it’s for you!
Keep reading if you want to learn more about how the site is built.
I love this description of the Go programming language from Rob Napier:
Go feels under-engineered because it only solves real problems. If you’ve ever worked in a wood shop, you’ve probably made a jig at some point. They’re little pieces of wood that help you hold plywood while you cut it, or spacers that tell you where to put the guide bar for a specific tool, or hold-downs that keep a board in place while you’re working on it. They’re not always pretty. They often solve hyper-specific problems and work only with your specific tools. And when you look at ones that have been used a lot, they sometimes seem a little weird. There might be a random cutout in the middle. Or some little piece that sticks off at an angle. Or the corner might be missing a piece. And when you compare them to “real” tools, “general” tools like you’d buy from a catalog, they’re pretty homey or homely depending on how you’re thinking about it.
But when you use one of them in your shop, you learn that the random cutout is because you store it against the wall and it would block the light switch otherwise. And if you put your hand on that little extra piece that sticks out, then the board won’t fall at the end of the cut. And the corner… well the corner is where you messed up when you were first making it and it’s kind of ugly, but it never actually matters when you use it. And that’s Go.
Point positive is a rafting term for agreeing in advance to point towards the safe way out of danger rather than towards the dangers themselves.
When you’re in trouble, don’t dwell on the cause, look for a solution. Only when the waters are calm, take a step back, reassess, and learn the necessary lessons to avoid it in the future.
Grandpa loved craft. […] He fixed things often and silently. Grandpa just cared about things working. He had an instinct for not just broken things but soon to be broken things. He would point out risky work, bad decision making in the form of shoddy materials or shifting angles.
As software developers, we often consider our trade to be unique. But what we (should) have in common with others is the mindset of respecting our craft—of producing solid and lasting work.
I have read a lot of long spiels about craft that frequently end in something like, software work isn’t like other work, and we shouldn’t be judged the same way. We are entirely unique. We are the special ones. I find this both saddening and unconvincing. I think that all labor is skilled labor. I think about the factories and the fields and the ways that demands for speed instead of cadence can hurt people. I think we should seek to understand and value our skills and see effort. But I don’t think we are going to fix anything about how software work is valued by refusing to let it belong to the rest of the world.
I love Laravel Forge’s quick deploy scripts. Forge allows you to set up a deploy script in their web interface and run it when you push to a git branch. However, I generally prefer to keep orchestration in the git repository. It’s nice to have history, and I don’t want to visit Forge whenever I want to make a change to the deploy script.
An elegant solution: move the script to a file. I created a deploy.sh and call it from Forge.
A few years ago I taught myself some Go. Not because I needed it but because I like poking around other ecosystems. I came across Go By Example, and it’s still is one of my favorite formats to explore a new language or framework.
The examples are succinct and introduce you to a concept without overwhelming you. This format will not turn into an expert, but is just enough to get you curious and kickstart your own explorations.
A green test suite is a blank canvas, and a blank canvas is a paralyzing place to start.
A failing test is a pointer to the next step. When I end the day with a failing test, I know exactly where to begin when I get back. The perfect kickstart to get into flow.
The past few years I’ve seen more projects use Go or Rust for heavy lifting alongside a higher-level language like PHP or JavaScript.
I’ve learned a little Go myself but don’t know enough about Rust to understand when you’d choose one over the other. Vercel is currently migrating a codebase from Go to Rust, it’s interesting to read the reasoning behind the decision.
For example:
Go’s preference for simplicity at the filesystem was creating problems for us when it came to file permissions. Go lets users set a Unix-style file permission code: a short number that describes who can read, write, or execute a file.
While this sounds convenient, this abstraction does not work across platforms; Windows actually doesn’t have the precise concept of file permissions. Go ends up allowing us to set a file permission code on Windows, even when doing so will have no effect.
In contrast, Rust’s explicitness in this area not only made things simpler for us but also more correct. If you want to set a file permission code in Rust, you have to explicitly annotate the code as Unix-only. If you don’t, the code won’t even compile on Windows. This surfacing of complexity helps us understand what our code is doing before we ever ship our software to users.
Next to PHP, Go is a low-level language—but Rust is even lower. Looks like Go is great for heavy lifting on the web, but if you’re into building tools to run in different environments Rust is where you want to be.
I used to leave pull request descriptions empty. “Let the code speak for itself” or “let the commits speak for themselves” are the perfect getaway from the extra work of documenting your thought process.
Recently, I’ve experienced that spending time on a good description is a worthwhile investment.