TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
View Poll Results: Do you add a space after your if/else/while/for/etc?
Yes 9 56.25%
No 7 43.75%
Who cares! 0 0%
Voters: 16. You may not vote on this poll

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 01-06-2008, 03:55 PM   #1 (permalink)
The Reckoner
Advanced Programmer Top Contributor 
 
Karl's Avatar
 
Join Date: Sep 2007
Posts: 437
Thanks: 22
Karl is on a distinguished road
Default A space or not?

OK, maybe it's just me, but I'm sick of people not adding a space after their if/else/while/etc. keywords. It really annoys me, it's not a function, so add a bloody space!

Just curious, where does everyone stand on this issue? I'm expecting to be a minority here, it seems everywhere I look people are omitting those spaces.

Example:

PHP Code:
if($something SOMETHING_FLAG
compared to:

PHP Code:
if ($something SOMETHING_FLAG
__________________
Any fool can write code that a computer can understand. Good programmers write code that humans can understand.
Karl is offline  
Reply With Quote
Old 01-06-2008, 04:08 PM   #2 (permalink)
The Wanderer
 
YouNeek's Avatar
 
Join Date: Jan 2008
Location: Herefordshire, United Kingdom
Posts: 9
Thanks: 1
YouNeek is on a distinguished road
Default

Personally I used to not add a space but in recent months I've decided it makes the code look a lot tidier and more conventional. It doesn't bother me if people don't, but I think it always looks nicer if people do.
__________________
YouNeek - Bit of a nutty one!
HappySlapCulture | MadCoffeeHouse | LedburyRd | CoffeeBean
Send a message via MSN to YouNeek Send a message via Skype™ to YouNeek
YouNeek is offline  
Reply With Quote
Old 01-06-2008, 04:14 PM   #3 (permalink)
The Visitor
 
short's Avatar
 
Join Date: Jan 2008
Posts: 3
Thanks: 0
short is on a distinguished road
Default

PHP Code:
if ( $something SOMETHING_FLAG 
that's the only right thing to do :)
short is offline  
Reply With Quote
Old 01-06-2008, 04:16 PM   #4 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

You're twisting things, short! I don't often put a space, but then again I don't pay much attention to the possibility of a space there. Zend actually gives me a space automatically if I press tab on the autocomplete list, but I tend to type them all myself and keep well away from the tab.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 01-06-2008, 05:07 PM   #5 (permalink)
The Addict
 
Join Date: Nov 2007
Posts: 264
Thanks: 2
TlcAndres is on a distinguished road
Default

It seems once again I've committed an error haha, I'll make sure to keep the space in mind from now on.
TlcAndres is offline  
Reply With Quote
Old 01-06-2008, 06:06 PM   #6 (permalink)
The Frequenter
 
Join Date: Dec 2007
Location: In my basement
Posts: 386
Thanks: 47
Aaron is on a distinguished road
Default

It is just personal preference... I like to style my if's like below:
PHP Code:
if(2){
   echo 
"LIES!";
}else(
   echo 
"MORE LIES!";

Send a message via MSN to Aaron
Aaron is offline  
Reply With Quote
Old 01-06-2008, 07:13 PM   #7 (permalink)
The Reckoner
Advanced Programmer Top Contributor 
 
Karl's Avatar
 
Join Date: Sep 2007
Posts: 437
Thanks: 22
Karl is on a distinguished road
Default

Yeh there is no right or wrong way, I just like to rant. Although, of course, I would say my way is the right way
__________________
Any fool can write code that a computer can understand. Good programmers write code that humans can understand.
Karl is offline  
Reply With Quote
Old 01-06-2008, 08:27 PM   #8 (permalink)
The Acquainted
 
Join Date: Sep 2007
Location: Arizona
Posts: 114
Thanks: 10
Andrew is on a distinguished road
Default

Also, I like adding the space, as it's more flowing. You don't do: (Well, most don't do:)
PHP Code:
$var='var'
So if you add a space between those, and all the loops/statements, then it just looks a lot better, not so cramped.
Send a message via AIM to Andrew Send a message via MSN to Andrew
Andrew is offline  
Reply With Quote
Old 01-06-2008, 08:41 PM   #9 (permalink)
The Frequenter
Newcomer 
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
xenon is on a distinguished road
Default

I personally hate space after language constructs. I use this style:

PHP Code:
if( $something SOMETHING_FLAG )
{
    
// do stuff...

But then again, it's a matter of preference... And about the poll, the 2nd option is not fair at all.
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
xenon is offline  
Reply With Quote
Old 01-06-2008, 09:14 PM   #10 (permalink)
Super Moderator
Advanced Programmer 
 
bluesaga's Avatar
 
Join Date: Sep 2007
Posts: 165
Thanks: 0
bluesaga is on a distinguished road
Default

always done it without the space, strange. It annoys me when things arent lined up (and really make things less usable to make them look nicer....) But that has never bugged me, strange that!
__________________
Halo 3 Cheats
bluesaga is offline  
Reply With Quote
Old 01-06-2008, 09:33 PM   #11 (permalink)
The Reckoner
Advanced Programmer Top Contributor 
 
Karl's Avatar
 
Join Date: Sep 2007
Posts: 437
Thanks: 22
Karl is on a distinguished road
Default

Quote:
Originally Posted by xenon View Post
And about the poll, the 2nd option is not fair at all.
Lol, no it isn't, I shall even the playing field
__________________
Any fool can write code that a computer can understand. Good programmers write code that humans can understand.
Karl is offline  
Reply With Quote
Old 01-06-2008, 10:44 PM   #12 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

I generally (note: not always as there are exceptions!) follow the idea of adding a space between language construct and opening parenthesis, and no space between function name and opening parenthesis. That's always true for functions, but I commonly neglect the space for isset/unset/empty and probably some others that my mind doesn't want to conjure up at this moment.

Back to the original poll question, I always add a space after if, else, while and for. (Note: if you ever see code from me without that space, don't shoot me. It's likely just a typing mistake.)
Salathe is offline  
Reply With Quote
Old 01-07-2008, 04:58 AM   #13 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

No, I find it easier to read with no space.
__________________

Village Idiot is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 12:43 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design