To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
PHPBuilder.com  
 

 

Go Back   PHPBuilder.com > PHP Help > Code Critique

Code Critique Having someone critique your code is always a great way to hone the skills. Stop in and post your code to see what your peers may have done differently.

Reply
 
Thread Tools Rate Thread Display Modes
Old 10-04-2003, 07:32 PM   #1
[e]r!k
Xpert
 
Join Date: Aug 2003
Location: Örebro, Sweden
Posts: 48
Post Spaces instead of tabs.

I'm using spaces instead of tabs since tabs are not the same in all programs. What do you think of this? Maybe you're doing the same?
[e]r!k is offline   Reply With Quote
Old 10-04-2003, 07:47 PM   #2
Moonglobe
Better fan than rebelo!
 
Moonglobe's Avatar
 
Join Date: Apr 2003
Location: brain://localhost:left-side
Posts: 2,381
for the second time today:

tabs suck.


my current style is like this:
PHP Code:
if ($condition)
{
    
//1 brace per line, 4 space indent per level
}
__________________
there's no place i can be, since i found serenity.
Moonglobe is offline   Reply With Quote
Old 10-04-2003, 09:32 PM   #3
jebster
Some clever title
 
Join Date: Sep 2002
Location: At home...
Posts: 649
Quote:
Originally posted by Moonglobe
for the second time today:

tabs suck.


my current style is like this:
PHP Code:
if ($condition)
{
    
//1 brace per line, 4 space indent per level
}
I only do 2 spaces cause when I used 4 the code didn't like fitting in the screen always!
__________________
Jebster
jebster is offline   Reply With Quote
Old 10-04-2003, 10:09 PM   #4
drawmack
Computers can do that?
 
drawmack's Avatar
 
Join Date: Apr 2003
Location: Pocono Mtns PA
Posts: 3,268
the coding standard that I use recommends spaces instead of tabs because tabs vary from program to program. For number of spaces it's a bit squishing saying should be 3 or 4 but must be consistent once a number is choosen.
drawmack is offline   Reply With Quote
Old 10-05-2003, 12:42 AM   #5
Weedpacket
Custom User Title™
 
Weedpacket's Avatar
 
Join Date: Aug 2002
Location: Rapid Offensive Unit "Foreign Object Damage"
Posts: 19,124
The style I've tended to settle on is to use tabs for primary indenting only, and spaces for all other - er, spacing.
PHP Code:
function_foo()
{
    
$oink_=_bar();
    for(
$i=0;_$i<10;_$i++)
    {
        
$baz____=_'This';___________//_Baz_is_that
        
$wibble_=_'Something_Else';_//_While_Wibble_is_something_else.
        
switch($oink[$i])
        {
        
case_1:
            
blink();
            break;
        
case_2:
            
barf();
            break;
        
case_3:
            
boggle();
            break;
        default:
            
crash_and_burn();
        }
    }
    
$smoo_=_array_pop($oink);
    
echo_($smoo=='whatever')
    
_____?_"Smoo_is_whatever"
    
_____:_"Smoo_isn't.";
}
(Where I've used '_' instead of space so's you can tell them apart from
tabs without having to cut-and-paste it all yourself).

If I was writing more densely (as I tend to do), I'd gobble a line or so by going
PHP Code:
function_foo()
{    
$oink_=_bar();
    for(
$i=0;_$i<10;_$i++)
    {    
$baz____=_'This';___________//_Baz_is_that
Tab damage should only throw off formatting in the second case, and even then only if tabs are one character wide....
__________________
On two occasions I have been asked [by Members of Parliament], "Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?" I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question.

Last edited by Weedpacket; 10-06-2003 at 04:51 PM.
Weedpacket is offline   Reply With Quote
Old 10-05-2003, 01:14 AM   #6
laserlight
PHP Witch
 
laserlight's Avatar
 
Join Date: Apr 2003
Location: Singapore
Posts: 12,388
Excluding any holy war on where exactly braces should be placed, I tend to use Weedpacket's version.

I usually use 4 space indents though, since 8 seems rather extreme to me, even if it is more "traditional".
2 doesnt quite give the visual differentiation of indent levels.
__________________
Use Bazaar for your version control system
Read the PHP Spellbook
Learn How To Ask Questions The Smart Way
laserlight is offline   Reply With Quote
Old 10-06-2003, 04:21 AM   #7
bad76
GuruMeditation #8401.0007
 
bad76's Avatar
 
Join Date: May 2003
Location: Italy
Posts: 1,213
Quote:
Originally posted by laserlight
Excluding any holy war on where exactly braces should be placed, I tend to use Weedpacket's version.

Too late warning , in the forum there is already any thread about this...



I agree with weedpacket too, but i'm used to not put blank in the code... ($baz='This';...)
__________________
It's statistically proven that anything can be proven by means of statistics...
bad76 is offline   Reply With Quote
Old 10-06-2003, 01:39 PM   #8
dotwebbie
Expert at something . . .
 
Join Date: Aug 2002
Posts: 287
Hrm. I'm probably going to get pummeled, but I like to use the phpBB Coding Standards.

http://area51.phpbb.com/docs/guide-standards.html

I'm currently using them for the Site Control project (not to be confused with SiteControl ). There are some things in the standards docs that I disagree with, but for the most part, it makes code much easier to read and for someone else to go through and see what is happening.

Last edited by dotwebbie; 10-06-2003 at 01:42 PM.
dotwebbie is offline   Reply With Quote
Old 10-06-2003, 02:09 PM   #9
pyro
W3C &amp;&amp; PHP
 
pyro's Avatar
 
Join Date: Dec 2002
Posts: 615
I do it the same way that Weedpacket, or depending on what laserlight ment about the braces, perhaps her way...
__________________

Personal website http://www.ryanbrill.com/
Business site: http://www.infinitywebdesign.com

If you’re not using valid HTML, then you haven’t created a Web page. You may have created something else, but it isn’t a Web page. - Joe Clark
pyro is offline   Reply With Quote
Old 10-06-2003, 02:13 PM   #10
stolzyboy
Super Moderator
 
stolzyboy's Avatar
 
Join Date: Sep 2002
Location: Fargo, North Dakota
Posts: 6,647
Quote:
Originally posted by pyro
I do it the same way that Weedpacket, or depending on what laserlight ment about the braces, perhaps her way...
me too...

PHP Code:
for ($i = 0; $i < $outer_size; $i++)
{
   for (
$j = 0; $j < $inner_size; $j++)
   {
      
foo($i, $j);
   }
}
__________________

http://www.codesight.net - Custom Web Development, Web Hosting, Web Consulting
stolzyboy is offline   Reply With Quote
Old 10-06-2003, 02:31 PM   #11
pyro
W3C &amp;&amp; PHP
 
pyro's Avatar
 
Join Date: Dec 2002
Posts: 615
I'd code that as such:

PHP Code:
for ($i=0; $i<$outer_size; $i++) {
    for (
$j=0; $j<$inner_size; $j++) {
        
foo($i, $j);
    }
}
__________________

Personal website http://www.ryanbrill.com/
Business site: http://www.infinitywebdesign.com

If you’re not using valid HTML, then you haven’t created a Web page. You may have created something else, but it isn’t a Web page. - Joe Clark
pyro is offline   Reply With Quote
Old 10-06-2003, 03:42 PM   #12
stolzyboy
Super Moderator
 
stolzyboy's Avatar
 
Join Date: Sep 2002
Location: Fargo, North Dakota
Posts: 6,647
Quote:
Originally posted by pyro
I'd code that as such:

PHP Code:
for ($i=0; $i<$outer_size; $i++) {
    for (
$j=0; $j<$inner_size; $j++) {
        
foo($i, $j);
    }
}
oops, the me too was supposed to be for dotwebbie

i like them so you can look up and down and see them... not right after the condition
__________________

http://www.codesight.net - Custom Web Development, Web Hosting, Web Consulting
stolzyboy is offline   Reply With Quote
Old 10-06-2003, 09:12 PM   #13
pyro
W3C &amp;&amp; PHP
 
pyro's Avatar
 
Join Date: Dec 2002
Posts: 615
That's how I used to do it, but then I fell under the influence of a Java programmer...
__________________

Personal website http://www.ryanbrill.com/
Business site: http://www.infinitywebdesign.com

If you’re not using valid HTML, then you haven’t created a Web page. You may have created something else, but it isn’t a Web page. - Joe Clark
pyro is offline   Reply With Quote
Old 10-06-2003, 10:52 PM   #14
Moonglobe
Better fan than rebelo!
 
Moonglobe's Avatar
 
Join Date: Apr 2003
Location: brain://localhost:left-side
Posts: 2,381
Quote:
Originally posted by dotwebbie
Hrm. I'm probably going to get pummeled, but I like to use the phpBB Coding Standards.

http://area51.phpbb.com/docs/guide-standards.html

I'm currently using them for the Site Control project (not to be confused with SiteControl ). There are some things in the standards docs that I disagree with, but for the most part, it makes code much easier to read and for someone else to go through and see what is happening.
I agree with everything in that except for tabs, and the only thing i do wrong is the use of the ternary operator for REALLY complex things. So that's why i could read the phpBB source so easily....
__________________
there's no place i can be, since i found serenity.
Moonglobe is offline   Reply With Quote
Old 10-06-2003, 11:40 PM   #15
planetsim
code | beer > sleep
 
Join Date: Sep 2002
Location: aus
Posts: 4,826
i use to be a "tab" er but i like to have only 2spaces.

But i guess it comes down to personal preference and if your working in a team the coding standard.
__________________
Dont be lazy Search
And use the Manual
Webmobo - Open Source News Script | Portfolio / Blog | Against TCPA
planetsim is offline   Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT -4. The time now is 06:25 PM.






Acceptable Use Policy

internet.comMediabistrojusttechjobs.comGraphics.com

WebMediaBrands Corporate Info


Advertise | Newsletters | Feedback | Submit News

Legal Notices | Licensing | Permissions | Privacy Policy


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.