I see your point and I agree to some extent. But the main reason you apply Yoda conditions is to fail first.
Basically it's the same reason why you have declare(strict_types=1); on the first line of your code.
Yes, readability is somewhat shattered but you gain better control over your code flow. Especially when you're developing for resilience. In huge codebases normal condition statements are overlooked and tests don't cover these conditions. Especially when dealing with legacy code.
I see your point and I agree to some extent. But the main reason you apply Yoda conditions is to fail first.
Basically it's the same reason why you have
declare(strict_types=1);
on the first line of your code.Yes, readability is somewhat shattered but you gain better control over your code flow. Especially when you're developing for resilience. In huge codebases normal condition statements are overlooked and tests don't cover these conditions. Especially when dealing with legacy code.
You can still use code review and linters with legacy code though. And unit tests, if you can decouple new code you introduce from the legacy code.
What do you mean by that exactly?