I'm currently organising the third edition Full Stack Europe. It's a conference in Antwerp, Belgium in October for developers who want to learn across the stack. We have a great line up with lots of familiar faces! Register your ticket now!
Have you every come across confusing if statements with complex conditionals such as this? I bet you did!
// please kill me 🤯
if (!(($this->shipping_country == "GB" || (strcmp($this-status, "Valid") !== 0)) {
To me, this is completely unreadable.
In the video below I show how I deal with this situation. Spoiler: add some tests around it and break the conditionals apart.
This video is part of the Mailcoach video course. It contains many more videos on how to write clear code. You can use this coupon code to get a nice discount of $10.
YES-I-WANT-TO-WRITE-READABLE-CODE
You can follow me on these platforms:
On all these platforms, regularly share programming tips, and what I myself have learned in ongoing projects.
Every month I send out a newsletter containing lots of interesting stuff for the modern PHP developer.
Expect quick tips & tricks, interesting tutorials, opinions and packages. Because I work with Laravel every day there is an emphasis on that framework.
Rest assured that I will only use your email address to send you the newsletter and will not use it for any other purposes.
Comments powered by
Laravel Comments
Want to join the conversation?
Log in or
create an account to post a comment.
1/ @freekmurze shares a video where he explains how to refactor complex if statements and making your code more readable as well as maintainable 😎
twitter.com/freekmurze/sta…
if (!$this->isNotAlmostTrue(!$uncertain)) { ... }
This one is much pretty than those I've seen.
😍 I generally prefer to use "private" methods, and then switch to "protected" if needed. But 99% of my favorites developers use "protected" most of the time. Am I missing something?
Also, while I have your attention. I’ve seen most of your tweets for the last couple of weeks. I’ve come to the conclusion that you are either a set of identical triplets or a robot. Nobody does that much in 24 hours. Which is it?
It's good to learn from those videos too, quality material! 👌
Watch those videos closely, Mattias :-)
Nah, you’re already doing lots of good stuff, specially adding tests with each PR 👍
I think in the client projects where I work in it doesn’t make a lot of difference. In open source it’s nice for package users to have an escape hatch and not to hammer everything down with private (and final).
This if statement make me a little sick.
total syntax error too! 😱
What are your thoughts on "How to refactor complex if statements"?