Reading List
The most recent articles from a list of feeds I subscribe to.
Jason Fried: 'Delegating projects, not tasks'
When you define too much work up front, you add unnecessary management overhead. More importantly, you create a bias and stifle a team’s creativity to solve the problem.
No one defines all the work up front. That’s a fools errand. Assuming you know too much up front is the best way to find out you’re wrong in the end. Instead we define the direction, the purpose, the reason, and a few specific “must haves” up front. The rest — all the rest, which is mostly everything — is determined during the project, by the people on the project.
Comparing two database columns in Laravel
When you want to compare two database columns in Laravel, you can’t use where because it treats the argument you’re comparing to as a value.
Instead, Laravel has a whereColumn method you can use to compare a value to another column’s value.
// Retrieve posts that were updated after
// they were published.
Post::query()
->whereColumn('updated_at', '>', 'published_at')
->get();
Clean code has room to breath
Timeless advice from Freek & Brent.
Just like reading text, grouping code in paragraphs can be helpful to improve its readability. We like to say we add some “breathing space” to our code.
$page = $this->pages()->where('slug', $url)->first();
if (! $page) {
throw new Exception();
}
$page = $this->pages()->where('slug', $url)->first();
if (! $page) {
throw new Exception();
}
Just one line of space can make the difference.
Elise Hein: 'Fighting inter-component HTML bloat'
As I’m refactoring an existing design system, this article by Elise Hein came quit timely.
We consider HTML to be cheap, but wrapping divs in divs in divs comes with a cost that slowly creeps up.
Why avoid extra wrapper elements?
- Bloated html hurts performance
- Redundant elements can create problems with accessibility
- Redundant elements can break styling
- Deeply nested dom trees are annoying to work with
Eager load relations in Laravel using withWhereHas
When using whereHas in Laravel, it’s not uncommon to also eager load the relation using with.
$posts = Post::query()
->with('author')
->whereHas('author', function (Builder $query) {
$query->where('name', 'Seb');
})
->get();
Laravel also has a more succinct method that combines the two: withWhereHas.
$posts = Post::query()
->withWhereHas('author', function (Builder $query) {
$query->where('name', 'Seb');
})
->get();