DEV Community

Discussion on: A simple tip for cleaner code

Collapse
 
mortoray profile image
edA‑qa mort‑ora‑y

What about:

        function foo($bar)
        {
            $value = '';            

            if ($bar > 0) {
                $value = "YES";
            } else if ($bar == 0) {
                $value = "MAYBE"
            } else {
                $value = "NO";
            }



            foo( $value );
            return $value;
        }

The simple addition of foo makes the second form entirely reasonable.

Without knowing the history of the code it's hard to say why it's ended up at the form it currently has. It's way too easy to look at things in isolation and find fault with them, or draw conclusions about what is clean/bad.

Collapse
 
alainvanhout profile image
Alain Van Hout

Please extract the middle part as a separate function and resubmit your pull request ;-p :-).