Posts tagged with best practices

Forget about component lifecycles and start thinking in effects

sebastiandedeyne.com

In a new blogpost, my colleague Seb explains why you should and how you can use useEffect.

React recently introduced a new way to deal with side effects: the useEffect hook. Translating lifecycle methods to useEffect calls can be confusing at first. It’s confusing because we shouldn’t be translating imperative lifecycle methods to declarative useEffect calls in the first place.

Read more [sebastiandedeyne.com]

Join thousands of developers

Every two weeks, I share practical tips, tutorials, and behind-the-scenes insights from maintaining 300+ open source packages.

No spam. Unsubscribe anytime. You can also follow me on X.

Learning Laravel - Observations, part 1: The service container

matthiasnoback.nl

Matthias Noback wrote down some thoughts on the Laravel container

Laravel's service container looks great. I like the idea that it can figure things out mostly by itself. I like that it's PHP-based, and that its syntax is quite compact. I think that most of the convenience functions (e.g. resolve()) and exotic options (like $this->app->resolving()) should be ignored. The best thing you can do for your application in the long term is to let all your services use dependency injection, and to inject only constructor arguments. This keeps things simple, but also portable to other frameworks with other dependency injection containers, or other architectural styles, when the time is there.

Read more [matthiasnoback.nl]

Tests and types

stitcher.io

My colleague Brent wrote another excellent blog post, this time on tests and types.

So while strong types can help us to ensure program correctness, some tests will always be a necessity to ensure business correctness. It's a matter of "both and", not "either or".

Read more [stitcher.io]

Internal classes in PHP

nunomaduro.com

Nuno Maduro, engineer at Algolia, explains what is the value of the @internal tag

The PHP @internal tag can be used to denote that the associated class/method is internal to the library. It's supported by PHPStorm and it warns people that those classes/methods are not meant to be used

Read more [nunomaduro.com]

Sharing learning via code

stakeholderwhisperer.com

Konstantin Kudryashov, one of the speakers at the upcoming Full Stack Europe conference, makes the case for sharing new insights early.

When you build new feature as a team, and it requires a lot of new learning, do not hoard new knowledge in your head. Instead, incrementally commit each unit of learning into working code. Hide that partial logic behind a feature flag. The feature would be incomplete, but work-in-progress outputs will expose meaningful and demonstrable progress. To increase team’s awareness of outputs, add links into the feature tracker or documentation.

Read more [stakeholderwhisperer.com]

Exceptional Exceptions

engagor.github.io

At the Clarabridge Developers blog, Toon Daelman wrote a good post on how to improve your exceptions.

You've made it to this post thinking "Why do we still need to talk about Exceptions?". Well, they're used everywhere in OOP codebases, but sometimes they're used in a way that make debugging a bit difficult. Let's look at some ways to make debugging exceptions a bit more fun!

Read more [engagor.github.io]

Read-Writable Regular Expressions

nasamuffin.github.io

Emily Shaffer makes the case for commenting regular expressions.

It’s probably not a good idea to encourage your coworkers to think critically about what life would be like if you got hit by a bus, but the good news is that you can simultaneously document your regular expression and teach your coworkers some regex basics, if you comment them carefully!

Read more [nasamuffin.github.io]

When to use Gate::after in Laravel

by Freek Van der Herten – 4 minute read

In a Laravel app policies are a great way to organize authorization logic that revolves around models.

For the longest time, I've been using Gate::before to allow superadmins to do anything they want. While working on a new app, it finally clicked how Gate::after can be useful too. I'd like to share that knowledge in this blog post.

Read more

Unsafe SQL functions in Laravel

stitcher.io

My colleague Brent offers some more details on the intricacies of Laravel's query builder.

I recently learned that not all query builder functionality in Laravel is "safe". This means that user input shouldn't be passed directly to it, as it might expose your application to SQL injection vulnerabilities.

Read more [stitcher.io]

20 unknown gems of Laravel

meramustaqbil.com

KH. Jebran Ali lists a few cool Laravel tricks

Laravel is full of hidden gems that I have discovered during working on different tasks. Some of these gems were less-known or un-documented features, functions parameters and hacks. In this blog post I will share those hidden gems with you, let’s get started.

Read more [meramustaqbil.com]

Fake PHP version in composer

afilina.com

Anna Filina explains the handy platform option you can use in composer.json. It's a good idea to just use this in all of your projects.

Say you run the latest PHP version on your machine, but the server runs PHP 5.5. This means that when you decide to add a Composer package, it might propose a version that may not be installable on the server. The solution is surprisingly easy. You can instruct Composer to see the PHP version of your choosing.

Read more [afilina.com]

Strategies for dealing with environment variables

marijn.huizendveld.com

Here's an interesting approach to work with env variables proposed by Marijn Huizendveld

Frameworks offer tools to parameterize environments in a variety of ways. But because of this configuration files of projects tend to get messy once projects are taken into production. Specifying purpose of the parameter within the name can help identify unneeded configurations. Making configuration explicit within the application layer can be even more helpful. Doing so eases refactoring and provides potential to improve the overall developer experience.

Read more [marijn.huizendveld.com]