Your code format

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Kyori
Forum Newbie
Posts: 23
Joined: Mon Oct 14, 2002 5:23 am
Contact:

how about this one?

Post by Kyori »

for($ey=$y-4,$a=0;$ey!=$y+5;$ey++)
for($ex=$x-4;$ex!=$x+5;$ex++,$a++)
if($row[0] == $ex && $row[1] == $ey)
$critters[a]++;


OR

for($ey=$y-4,$a=0;$ey!=$y+5;$ey++)
{
for($ex=$x-4;$ex!=$x+5;$ex++,$a++)
{
if($row[0] == $ex && $row[1] == $ey)
{
$critters[a]++;
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

not using code/php-block here your whitespaces are skipped by html ;)
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

Usually if you came from C++, you'd do your if, while, for's like:

Code: Select all

<?php
if ($var == 1)
    {
     echo $var;
     }

?>
But, if you came directly to PHP, like me, you'd use:

Code: Select all

<?php
if ($var == 1) {
echo $var;
}
?>
Image Image
DeGauss
Forum Contributor
Posts: 105
Joined: Tue Oct 22, 2002 9:44 am
Location: Gainesville, FL

Post by DeGauss »

Depending on how far i think i'm going to nest if...else stuff...

if ($blah) {
<tab>print "spoon\n";
}

if i've got something that spans multiple lines, i do the following:

if (!$_POST["polNumber"]) { $_SESSION["polNumber"]=NULL; unset($_SESSION["polNumber"]); $_SESSION["errPN"]=1; } else { $_SESSION["errPN"]=NULL; unset($_SESSION["errPN"]); $_SESSION["polNumber"]=$_POST["polNumber"]; }
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post by Takuma »

Mmmm

I've converted nearly all my spaces into tabs. I just thought the file size migh be smaller if I do this :D
User avatar
Heavy
Forum Contributor
Posts: 478
Joined: Sun Sep 22, 2002 7:36 am
Location: Viksjöfors, Hälsingland, Sweden
Contact:

Post by Heavy »

I usually try to put the first character indented to be vertically below the first non symbol character after the reserved word. And I keep doing so through nested braces.
Also, I like to indent function content so that only the word "function" is to the left:

Code: Select all

function MySub($blablabla)&#123;
         $blabla = "$blablabla no way";
         if (strlen($blabla) > 7)&#123;
             echo "DUMB";
         &#125;elseif (is_float($blablabla))&#123;
                  echo $blablabla / 4;
              &#125;else&#123;
                  echo "$blablabla divided by 4";
              &#125;
         $strSQL = "select passwords from databases all over the world!";
         $result = mysql_query($strSQL);
         while($row = mysql_fetch_array($result))&#123;
               echo "Password: &#123;$row&#1111;'pass']&#125;<br>";
         &#125;
&#125;
... at least using syntax hiliting it is easy to read... I think...

I hate tabs...
But I am still considering using them because I like to indent much, and tabs require less bytes.
Takuma wrote:I've converted nearly all my spaces into tabs. I just thought the file size migh be smaller if I do this :D
Post Reply