| | Submitted on: 3/5/2001 8:39:35 PM
By: Steve Oliver
Level: Beginner User Rating:
By 6 Users Compatibility:PHP 3.0, PHP 4.0
Users have accessed this article 6672 times. | (About the author) |
| | Teaches the basics of Proper Indentation in your php source. | |
|
Terms of Agreement:
By using this article, you agree to the following terms...
1) You may use
this article in your own programs (and may compile it into a program and distribute it in compiled format for langauges that allow it) freely and with no charge.
2) You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.
3) You may link to this article from another website, but ONLY if it is not wrapped in a frame.
4) You will abide by any additional copyright restrictions which the author may have placed in the article or article's description. | I think it is a basic coding standard to Indent each function, loop, etc. This not only helps others that may be working with your source, But it also helps when you go back and look at your source. Below are some examples of right and wrong.
wrong way:
if($foo==""){$var="1");}
should be:
if($foo=="")
{
$var="1";
}
wrong way:
While(List($blah)=mysql_fetch_row($results)){
if($blah==""){echo $blah;}else{echo "none";}}
should be:
While(List($blah)=mysql_fetch_row($results))
{
if($blah=="")
{
echo $blah;
}
else
{
echo "none";
}
}
wrong way:
function doit($var){
if($var==""){$var="false";}else{$var="true";}
return $var;}
should be:
function doit($var)
{
if($var=="")
{
$var="false";
}
else
{
$var="true";
}
return $var;
}
I think you get the basic Idea. Although it may seem long and drawn out, trust me, it will help you in the long run.
-Steve | |
Other 4 submission(s) by this author
|
|
|
Report Bad Submission |
|
|
Your Vote! |
See Voting Log |
|
Other User Comments |
3/8/2001 10:33:35 PM:Shaun Steve is right, although it may seem
like more coding up front, it'll help
you later when you need to read your
code. And if you're publishing code
that someone else will be reading or
using, it becomes even more important
that it's formatted in an easy-to-read
manner.
Another common convention is
to place the opening brace on the same
line as the start of the function
definition, loop call,
etc:
while(1){
echo
|
9/7/2001 7:34:59 AM:Matthias I agree to Shaun, that there is not
only one way to format source
code.
I use the same formatting as
Shaun
<pre>
function xyz()
{
print
|
9/13/2001 9:58:43 PM:Rob Loach I have a habbit of
doing:
if($var==""){
$var="false";
}
(having the first
bracket on the first line)
I find that
this is very good. I know that it is
neater to have the bracket on a new
line, but I really don't like to scrool
up and down my code alot.
|
|
Add Your Feedback! |
Note:Not only will your feedback be posted, but an email will be sent to the code's author in your name.
NOTICE: The author of this article has been kind enough to share it with you. If you have a criticism, please state it politely or it will be deleted.
For feedback not related to this particular article, please click here. |
|