DEV Community

JohnDivam
JohnDivam

Posted on • Updated on

Avoid negative conditionals , clean code

Avoid negative conditionals
Certainly! Writing clean and readable PHP code involves avoiding negative conditionals and using positive conditionals instead. Negative conditionals can make the code harder to understand and follow. Here's an example of how you can refactor code to avoid negative conditionals:

code with negative conditionals (Bad):

function isNotParent($node) : bool 
{

}
Enter fullscreen mode Exit fullscreen mode

code with positive conditionals (Good):

function isParent($node) : bool 
{

}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)