logo
podcast Podcast
get help Get Unstuck

Keep your code consistent

Ever find 5 different ways of doing something in a single codebase? Here's an approach to minimize that.

Joel Clermont
Joel Clermont
2023-10-30

Laravel is continually adding new features and improving existing ones. And, as developers, we're always learning new ways to do things. So it's natural that over time, the way we write code will change.

If you're not careful, this can lead to a codebase that's inconsistent, which can make it harder to understand and maintain.

For example, I recently shared a tip on using custom Mockery matchers to clean up your tests. Would I just start writing new tests with this streamlined syntax, or should I go update all tests to use it?

In this case, because the change was 1. only in test code, 2. fairly mechanical to make, and 3. made the tests easier to read, I made the decision to go ahead and update all tests. This kept things consistent without introducing too much risk.

On the other hand, if the change was in application code, much more widespread in the codebase, or if the advantage of the new syntax was questionable, I might have decided to leave the existing code alone and just use the new syntax going forward. It's a decision you have to make for your project. But it should be a conscious decision, not something left to chance.

Here to help,

Joel

P.S. One area consistency is super important is data validation. That's one of the messages we weave through our book Mastering Laravel Validation Rules. It will improve the security of your application and the quality of your data.

Toss a coin in the jar if you found this helpful.
Want a tip like this in your inbox every weekday? Sign up below 👇🏼
email
No spam. Only real-world advice you can use.