How do you indent in your coding style?

  • gt8ost4l
  • Student
  • Student
  • User avatar
  • Posts: 99

Post 3+ Months Ago

looking at these posts made me rethink my ways in coding i was just wondering how do you guys indent your code
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9089
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

If you are referring to the way you format the code, I usually just use the tab key. When I was going to a university, my professor was very strict in that it had to be exactly 3 spaces for each indent, but in my opinion that is three times the amount of keystrokes as hitting the tab key once for an indent and all that does is slow the coding process down.
  • gt8ost4l
  • Student
  • Student
  • User avatar
  • Posts: 99

Post 3+ Months Ago

can you give me a example
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9089
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

Sure why not:

PHP Code: [ Select ]
<?php
 
//Lets do the loop
while($row = $db->sql_fetchrow($result))
{
   if($row['id'] == 0)
   {
      echo "Zero is okay I suppose.\n";
   }
   elseif($row['id'] == 5)
   {
      echo "Five is definetely better as its greater than zero.\n";
   }
   else
   {
      //lets use the id to loop through another array
      foreach($group_array[$row['id']] as $key => $value)
      {
         if($key == 'ozzu')
         {
            echo "You found the best forum!\n";
         }
         else
         {
            echo "You may want to keep looking!\n";
         }
         
         //Output the value
         echo "$value"; //Usually extremely high if key is equal to ozzu
      }
   }     
}
 
?>
  1. <?php
  2.  
  3. //Lets do the loop
  4. while($row = $db->sql_fetchrow($result))
  5. {
  6.    if($row['id'] == 0)
  7.    {
  8.       echo "Zero is okay I suppose.\n";
  9.    }
  10.    elseif($row['id'] == 5)
  11.    {
  12.       echo "Five is definetely better as its greater than zero.\n";
  13.    }
  14.    else
  15.    {
  16.       //lets use the id to loop through another array
  17.       foreach($group_array[$row['id']] as $key => $value)
  18.       {
  19.          if($key == 'ozzu')
  20.          {
  21.             echo "You found the best forum!\n";
  22.          }
  23.          else
  24.          {
  25.             echo "You may want to keep looking!\n";
  26.          }
  27.          
  28.          //Output the value
  29.          echo "$value"; //Usually extremely high if key is equal to ozzu
  30.       }
  31.    }     
  32. }
  33.  
  34. ?>
  • SpooF
  • ٩๏̯͡๏۶
  • Bronze Member
  • User avatar
  • Posts: 3422
  • Loc: Richland, WA

Post 3+ Months Ago

I use my tab key for indents but I always change my editors to insert spaces instead of tabs. When moving betweeen operating systems and displaying code on websites it just makes the formatting easier.
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

I'm curious as to whether using spaces instead of tabs can have a noticeable impact on execution performance in scripting languages such as Javascript or PHP. If you were to use 4 spaces in place of tabs, that would be 4 times as many bytes for the interpreter to look at while discarding whitespace tokens.
  • SpooF
  • ٩๏̯͡๏۶
  • Bronze Member
  • User avatar
  • Posts: 3422
  • Loc: Richland, WA

Post 3+ Months Ago

Im not sure how I would test that, Unless I was to take a framework and replace all tabs/spaces and then run a time trial on it.
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

I suppose it would be moot for Javascript if you're using something like the YUI compressor, which removes all whitespace anyways. Same goes for an opcode cache for PHP I guess.
  • AdamC
  • Beginner
  • Beginner
  • User avatar
  • Posts: 38

Post 3+ Months Ago

Whether I tab or not depends on what kind of work I'm doing. I've noticed that when I combine HTML and Javascript, sometimes it's safer to leave tabs out so I don't accidentally break my code.
  • righteous_trespasser
  • Scuffle
  • Genius
  • User avatar
  • Posts: 6230
  • Loc: South-Africa

Post 3+ Months Ago

My workplace is very specific on how code should be formatted so all of us internally know what's going on because we all conform to the same standards ... When coding HTML I will use 1 space:

HTML Code: [ Select ]
<div>
 <div>
  <h1>Heading</h1>
  <p>Paragraph</p>
 </div>
</div>
  1. <div>
  2.  <div>
  3.   <h1>Heading</h1>
  4.   <p>Paragraph</p>
  5.  </div>
  6. </div>


When coding php/javascript I use 2 spaces:

PHP Code: [ Select ]
<?php
  if(1 == 1){
    echo 'something';
    while($flag == true){
      //do something else
    }
  }
?>
  1. <?php
  2.   if(1 == 1){
  3.     echo 'something';
  4.     while($flag == true){
  5.       //do something else
  6.     }
  7.   }
  8. ?>
  • righteous_trespasser
  • Scuffle
  • Genius
  • User avatar
  • Posts: 6230
  • Loc: South-Africa

Post 3+ Months Ago

Bigwebmaster wrote:
PHP Code: [ Select ]
<?php
  //Output the value
  echo "$value"; //Usually extremely high if key is equal to ozzu
?>
  1. <?php
  2.   //Output the value
  3.   echo "$value"; //Usually extremely high if key is equal to ozzu
  4. ?>

nice. hehe
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9089
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

I was wondering when anybody would actually look at the code I wrote ;)
  • Karl_89
  • Banned
  • Banned
  • Karl_89
  • Posts: 1

Post 3+ Months Ago

I do Indent, it keeps stuff readable. Consider indenting by 2 spaces instead of 4 or 8. I only indent block elements, put the rest on a single line.

Post Information

  • Total Posts in this topic: 13 posts
  • Users browsing this forum: No registered users and 40 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.