Thursday, February 23, 2017

Coding don'ts: enourmous if blocks

When wading trough other peoples code I find these annoyingly large if structures, especially used inside while/foreach loops that check if some item is ok to process or not.

Especially in PHP code for some reason or another. It's like people don't know about continue.

Don't do this!

foreach ($something as $item) {
 if ($item) {
   ...
   .. screenfull of code ..
   ...
 }
}

Do this instead

foreach ($something as $item) {
 if (!$item)
   continue;

 ...
 .. screenfull of code ..
 ...
}

1 comment:

Pradeep Singh said...

All MNC company need l shaped modular kitchen designs for new look. Its help look and feel gud. Great Review thanks