marain
10-01-2012, 09:27 PM
Elegance, I suppose, can be subjective. I view
<?php
if ( $here === 'arson' )
echo '<body class = "arson">';
elseif ( $here === 'badcheck' )
echo '<body class = "badcheck">';
elseif ( $here === 'lewdness' )
echo '<body class = "lewdness">;
elseif ( $here === 'posswpn' )
echo '<body class = "posswpn">;
else echo '<body>';
?>
as less elegant than...
<?php
switch ($here) {
case 'arson':
echo '<body class = "arson">';
break;
case 'badcheck':
echo '<body class = "badcheck">';
breaK;
case 'lewdness':
echo '<body class = "lewdness">';
break;
case 'posswpn';
echo '<body class = "posswpn">';
break;
default:
echo '<body>';
}
?>
...even though I'm not sure I can verbalize why. Whether you agree or not, I suspect there are coding methods that improve on both of these snippets, with regard to elegance. I would welcome thoughts and suggestions.
A.
<?php
if ( $here === 'arson' )
echo '<body class = "arson">';
elseif ( $here === 'badcheck' )
echo '<body class = "badcheck">';
elseif ( $here === 'lewdness' )
echo '<body class = "lewdness">;
elseif ( $here === 'posswpn' )
echo '<body class = "posswpn">;
else echo '<body>';
?>
as less elegant than...
<?php
switch ($here) {
case 'arson':
echo '<body class = "arson">';
break;
case 'badcheck':
echo '<body class = "badcheck">';
breaK;
case 'lewdness':
echo '<body class = "lewdness">';
break;
case 'posswpn';
echo '<body class = "posswpn">';
break;
default:
echo '<body>';
}
?>
...even though I'm not sure I can verbalize why. Whether you agree or not, I suspect there are coding methods that improve on both of these snippets, with regard to elegance. I would welcome thoughts and suggestions.
A.