...

View Full Version : Code better?



Crisp
02-26-2009, 09:21 PM
Hey Guys.

I seriously don't know how to code "really" good.
I don't really know where to indent and not and stuff.

For example, for a table in HTML, look how I do it:


<table width="100%" height="50" cellpadding="6"
cellspacing="0" class="backtable">
<tr>
<td valign="top">Testing</td>
</tr>
</table>

For an echo and an if in php, I do this:



<?php
if($blah ==1)
{
echo "Yes";
}


I mean, am I doing this right? and is there a site that will show how to code better or something?
Another thing is, when the line is getting full (I know it shouldn't get too long) where do I break?

Thanks IA.

Majoracle
02-26-2009, 09:37 PM
There's no real right or wrong way. Like with PHP function hierarchy, most people do it by tag hierarchy, simply so the lower the risk of missing a closing tag. For the most part, you can do whatever is easiest for you to understand, because as far as the browser is concerned, it could all be crammed on one line. I do it like this:


<table width="100%" height="50" cellpadding="6" cellspacing="0" class="backtable">
<tr>
<td valign="top">Testing</td>
</tr>
<tr>
<td valign="top">Testing</td>
</tr>
</table>

<div id="id1">
<div id="id1-1">Testing</div>
<div id="id1-2">
<div id="id1-2-1">Testing</div>
</div>
</div>

<ul>
<li>List Item 1</li>
<li>List Item 2</li>
<li>List Item 3</li>
</ul>

Crisp
02-26-2009, 09:44 PM
Hmmm that looks really good. :)
Thanks a lot man. I'll do just like that (If you don't mind xD)

Thanks. :)

oesxyl
02-27-2009, 06:43 AM
you indent your code to make it easy to read and understand when you come back over it, That means anything is "right" when you feel that. :)
some people use to indend code like this:



if ( myfunc( $par1, $par2 ) == 1 )
{
callthisfunction( $otherpar );
}

I hate this, :)
I prefere this:


if(myfunc($par1, $par2) == 1){
callthisfunction($otherpar);
}

but that don't mean that the way I do it is "right" for somebody else, :)
In my opinion, feel free to choice your own style and that will be "right", :)

that don't apply when you work in a team, is obvious that you must adopt the team style, :)
best regards



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum