|
Posted by robert on 03/30/06 18:27
sermonette I.
to take geoff's great comments a bit further...if you want a job programming
in any language, it is best if you first read it's "best practices"
document(s) so that you use the same generally accepted syntax and
formatting as others in the field...even though alternate options may exist.
in the below code, all php tags should open and close at the left margin
except where they are actually in-line. some editors don't do colored
highlighting making it hard to tell where they start/end if the code is
formatted otherwise. always use the bracketing format to set the
function/loop body from the definition/condition. again, this throws a
wrench in the works for most editors...most editors *will* understand
bracketing and give a plethura of options for manipulating the stuff in
between. finally, *most* people place the first bracket just below the
function/loop that it begins.
i'm sure you are comfortable in using endif and endforeach, but when you
work with others on a project it's not about your comfort. it's about making
sure the next guy (whether a veteran of the company, a consultant, or first
day employee) who works with the code can easily read and traverse the logic
the script contains.
oh btw...if, while, foreach, etc. ARE NOT FUNCTIONS...there should be a
space between the word and the left parenthesis.
well shit! then there's the whole variable naming convention. some separate
words in variables using an underscore...some use camel casing while others
use pascal...and others use a combination of any of the three. you went half
way...form_errorlist s/b form_error_list or formErrorList or
FormErrorList...or Form_Error_List or... you may think that's picky, but how
many times do you get pissed off at php itself because of the same kind of
inconsistancy? they've got "isset" which follows NO naming
convention...they've got "is_array" which is better but i bet you've typed
"issarray" before and been pissed at the results!
and for gawd's sake, INDENT YOUR HTML...makes a hell of a difference in
debugging script output via viewing the source from the browser. as for
geoff's inline html echoing...if it gets more complex than that, it is very
hard to maintain (format, insertion of new content based on new
requirements, etc.). don't fuss about the number of times you specify and
open/close php tag.
it's all about maintenance. that's all just me (but not totally - read "code
complete")...and so's this:
(i think this would look even less cluttered by using short tags but i can't
always control that and long tags are sometimes an absolute must...say with
xml and php getting into the mix together)
<?php
if ($formErrorList)
{
?>
Please correct the following errors:
<br/>
<ul>
<?php
foreach ($formErrors as $error)
{
?>
<li><?php echo $error; ?></li>
<?php
}
?>
</ul>
<?
}
?>
| Also I've never used that syntax so I will substitute what I normally
| use.
|
| Try:
|
| <?php
| if($form_errorlist){ ?>
| Please correct the following errors:<BR>
| <UL>
| <?php foreach($form_errors as $val){ ?>
| <LI><?php echo $val; ?> </LI>
| <?php }?>
| </UL>
| <?php } ?>
|
| <?php
| if($form_errorlist){
| echo ' Please correct the following errors:<BR>\n<UL>';
| foreach($form_errors as $val){
| echo "<LI>$val</LI>";
| }
| echo '</UL>';
| }
| ?>
| --
| Geoff Berrow 0110001001101100010000000110
| 001101101011011001000110111101100111001011
| 100110001101101111001011100111010101101011
Navigation:
[Reply to this message]
|