[RFC & Patch][Implemented] Coding Guidelines

Note: We are moving the topics of this forum and it will be deleted at some point

Publish your own request for comments/change or patches for the next version of phpBB. Discuss the contributions and proposals of others. Upcoming releases are 3.2/Rhea and 3.3.
User avatar
Dr.Death
Registered User
Posts: 25
Joined: Thu Feb 24, 2005 10:33 am
Location: Germany
Contact:

Re: [RFC & Patch][Implemented] Coding Guidelines

Post by Dr.Death »

My favorites are:

- Using tabs instead of spaces
- Not using CamelCase. ( this_is_my_var_name_is_better_readable_and_easier_to_write )
- using extra lines for the brakets:

Code: Select all

if ($foo)
{
    echo "foo";
}
else
{
    echo "bar";
} 
Doc.

Image

User avatar
naderman
Consultant
Posts: 1727
Joined: Sun Jan 11, 2004 2:11 am
Location: Karlsruhe, Germany
Contact:

Re: [RFC & Patch][Implemented] Coding Guidelines

Post by naderman »

Dr.Death wrote:My favorites are:
What does this contribute to the discussion? I'm sure everyone here has their own favourites. But everyone naming them is not going to help us find a compromise. Do you have any suggestions for that?

User avatar
Highway of Life
Registered User
Posts: 1399
Joined: Tue Feb 08, 2005 10:18 pm
Location: I'd love to change the World, but they won't give me the Source Code
Contact:

Re: [RFC & Patch][Implemented] Coding Guidelines

Post by Highway of Life »

naderman wrote:Either way I think rather than discussing this any further we should focus on something more productive.
So do you want to lock this topic?
Image

User avatar
naderman
Consultant
Posts: 1727
Joined: Sun Jan 11, 2004 2:11 am
Location: Karlsruhe, Germany
Contact:

Re: [RFC & Patch][Implemented] Coding Guidelines

Post by naderman »

No I don't, I'm just saying I don't think we should drag this on for ever ;-) If there are any new arguments or ideas how to compromise or some such I'd be happy to hear them.

User avatar
naderman
Consultant
Posts: 1727
Joined: Sun Jan 11, 2004 2:11 am
Location: Karlsruhe, Germany
Contact:

Re: [RFC & Patch][Implemented] Coding Guidelines

Post by naderman »

code reader wrote:two things:
1) tabs vs. spaces:
if you want to use tabs, it requires discipline, especially when you need to break a long line for readability:
e.g., let's say you have a line that looks like so:

Code: Select all

'TAB_TAB'if (($some variable_with a long_name > 3 && $some variable_with a long_name < 17 && $today_is _tueseday) || $next_week_i_will_get_my_annual_bonus || $your_name == "AL")
 
such a line needs to be broken.
when breaking it, you should *not* use:

Code: Select all

'TAB_TAB'if (($some variable_with a long_name > 3 && $some variable_with a long_name < 17 && $today_is _tueseday) || 
'TAB_TAB_TAB'$next_week_i_will_get_my_annual_bonus || $your_name == "AL")
 
but rather:

Code: Select all

'TAB_TAB'if (($some variable_with a long_name > 3 && $some variable_with a long_name < 17 && $today_is _tueseday) || 
'TAB_TAB'"___"$next_week_i_will_get_my_annual_bonus || $your_name == "AL")
 
(i used _ to denote space)
in other words: <TAB> for indetation, and <sp> for tabulation when breaking long lines, otherwise things are completely messed when breaking long lines and different people use different TAB value.

since it isn't reasonable to expect coders to use this much discipline, it makes sense to avoid tabs altogether (of course, if long lines are never broken my argument is void, but this present even worse issues of readability)
Well the way it's in the coding guidelines and the way it has been handled in Olympus is that you use tabs for indentation and formatting. The formatting part requires you to set your tab width to 4 for it to look properly. It still looks ok with settings like 2 or 4, but usually doesn't align properly. Of course it then becomes questionnable whether you should use tabs if you require them to be represented by a particular amount of spaces. People seem to prefer editing with tabs however and as you said mixing tabs & spaces that way requires a lot of discipline so I think we can just go on the way it was in Olympus.

User avatar
Highway of Life
Registered User
Posts: 1399
Joined: Tue Feb 08, 2005 10:18 pm
Location: I'd love to change the World, but they won't give me the Source Code
Contact:

Re: [RFC & Patch][Implemented] Coding Guidelines

Post by Highway of Life »

naderman wrote:No I don't, I'm just saying I don't think we should drag this on for ever ;-) If there are any new arguments or ideas how to compromise or some such I'd be happy to hear them.
Okay... so at the risk of possibly dragging this on... :D

I’m a little confused here because you said we should follow PHP's project guidelines, but then I pointed out that what is currently in our guidelines for 4.0 doesn't match PHP's project guidelines, so what are we doing? Are we following their guidelines or are we making up new ones, is it personal preference? Because it’s different from both PHP and phpBB3's guidelines, and do we really want to change it that much, or are we trying to match other Frameworks, and which framework are we trying to match? - It has merit, but I believe there needs to be some kind of consistency or reason for going a completely different direction with regards to some of these guidelines. :)

I think it’s important because coding is a matter of style, and as you know many developers are picky about the way they like to code, you can’t please everybody, but I also believe it’s important to come to a consensus or at least a solid reason for going a specific direction, especially when it’s such a different style that everyone within phpBB might have gotten used to since phpBB3.
Last edited by Highway of Life on Sat Jan 23, 2010 10:15 pm, edited 1 time in total.
Image

User avatar
naderman
Consultant
Posts: 1727
Joined: Sun Jan 11, 2004 2:11 am
Location: Karlsruhe, Germany
Contact:

Re: [RFC & Patch][Implemented] Coding Guidelines

Post by naderman »

I was actually talking about these standards: http://groups.google.com/group/php-stan ... l-proposal

ToonArmy
Registered User
Posts: 335
Joined: Fri Mar 26, 2004 7:31 pm
Location: Bristol, UK
Contact:

Re: [RFC & Patch][Implemented] Coding Guidelines

Post by ToonArmy »

code reader wrote:as to the case of adding a second statement to a block and forgetting to add braces:
this can only happen if one is sloppy with indentation, which is a mortal sin and is much more important than the question of braces/no braces.
Even with proper indentation it's still easy to do.
Chris SmithBlogXMOOhlohArea51WikiNo support via PM/IM
Image

Nelsaidi
Registered User
Posts: 122
Joined: Tue Nov 11, 2008 5:44 pm

Re: [RFC & Patch][Implemented] Coding Guidelines

Post by Nelsaidi »

I'm not too sure on whats happening with phpBB4, however I would like to keep track of whats going on phpBB4, and give my two cents where/when I can. For camelCase over underscores , wouldnt it be best to follow whatever library you are building it on? I'm not too sure on SPL, but if that as used as the core then follow that, or if its Kohana then underscores, and if its Symfony then camelCase. This also brings up the issue of spaces/tabs because as far as I'm aware Symfony uses 2 spaces as opposed to tabs. However, the reason following the framework's standards is that if you are calling every class and method of that framework using underscores, but all phpBB functions using camelCase then consistency isnt mantained, and may cause confusion.

Feel free to correct me, I learn from my own mistakes :)

ToonArmy
Registered User
Posts: 335
Joined: Fri Mar 26, 2004 7:31 pm
Location: Bristol, UK
Contact:

Re: [RFC & Patch][Implemented] Coding Guidelines

Post by ToonArmy »

Nelsaidi wrote:I'm not too sure on SPL [...]
SPL isn't a framework, it's a library.
Nelsaidi wrote:[...] Kohana then underscores [...]
Not a fan of Kohana's naming or design.
Chris SmithBlogXMOOhlohArea51WikiNo support via PM/IM
Image

Post Reply