View Full Version : Code better?

Feb 26th, 2009, 10: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">
<td valign="top">Testing</td>

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

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.

Feb 26th, 2009, 10: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">
<td valign="top">Testing</td>
<td valign="top">Testing</td>

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

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

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

Thanks. :)

Feb 27th, 2009, 07: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){

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