[RFC|Merged] Javascript Coding Style

These requests for comments/change have lead to an implemented feature that has been successfully merged into the 3.1/Ascraeus branch. Everything listed in this forum will be available in phpBB 3.1.
_hsr
Registered User
Posts: 42
Joined: Mon Mar 26, 2012 7:06 am

[RFC|Merged] Javascript Coding Style

Post by _hsr » Thu Apr 19, 2012 6:22 am

Code: Select all

phpbb.attachment_lightbox() {
	this.init = function() {
		if(this.sources === undefined) {
			return this.addSources();
		}
		else {
			return this.enable();
		}
	}
}
This is a piece of code I'm working on right now, and I'd like to suggest the following changes:

Code: Select all

phpbb.add_ajax_callback = function(id, callback)
{
	if (typeof callback === 'function')
	{
		phpbb.ajax_callbacks[id] = callback;
	}
	return this;
}
be changed to

Code: Select all

phpbb.add_ajax_callback = function (id, callback) {
	if (typeof callback === 'function') {
		phpbb.ajax_callbacks[id] = callback;
	}
	return this;
}
Ticket
http://tracker.phpbb.com/browse/PHPBB3-10855

Patch
https://github.com/phpbb/phpbb3/pull/779
There is a text here !

User avatar
callumacrae
Infrastructure Team
Infrastructure Team
Posts: 1046
Joined: Tue Apr 27, 2010 9:37 am
Location: England
Contact:

Re: [RFC|Accepted] Coding Guideline Modifications

Post by callumacrae » Thu Apr 19, 2012 7:26 am

Your second example is wrong. It should be:

Code: Select all

phpbb.add_ajax_callback = function(id, callback) {
   if (typeof callback === 'function')
   {
      phpbb.ajax_callbacks[id] = callback;
   }
   return this;
}
Parentheses go on the same line with function expressions (but not function declarations) and objects.

I've proposed having parentheses on their own line in the 4.0 Coding Guidelines topic, feel free to go +1 it. It won't be done in 3.x.
Made by developers, for developers!
My blog

_hsr
Registered User
Posts: 42
Joined: Mon Mar 26, 2012 7:06 am

Re: [RFC|Accepted] Coding Guideline Modifications

Post by _hsr » Thu Apr 19, 2012 8:37 am

Parentheses?
Or do you mean curly braces?

And if you are saying the second one is wrong, as in this one:

Code: Select all

phpbb.add_ajax_callback = function(id, callback)
{
   if (typeof callback === 'function')
   {
      phpbb.ajax_callbacks[id] = callback;
   }
   return this;
}
It is from core.js, the original.

The function definition I suggested is this:

Code: Select all

phpbb.add_ajax_callback = function (id, callback) {
   if (typeof callback === 'function') {
      phpbb.ajax_callbacks[id] = callback;
   }
   return this;
}

edit: I've added a PR https://github.com/phpbb/phpbb3/pull/762/ if you all could comment there on the issues, it would be great.
There is a text here !

User avatar
callumacrae
Infrastructure Team
Infrastructure Team
Posts: 1046
Joined: Tue Apr 27, 2010 9:37 am
Location: England
Contact:

Re: [RFC|Accepted] Coding Guideline Modifications

Post by callumacrae » Thu Apr 19, 2012 9:09 am

Hm, that function was fine when I wrote it xD

You can't the curly braces in one place without changing them everywhere.
Made by developers, for developers!
My blog

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

Re: [RFC|Accepted] Coding Guideline Modifications

Post by naderman » Fri Apr 20, 2012 6:22 pm

Yes, this is a topic about coding guideline modifications. He is proposing to change the guidelines for Javascript code, and adapt all the code.

User avatar
callumacrae
Infrastructure Team
Infrastructure Team
Posts: 1046
Joined: Tue Apr 27, 2010 9:37 am
Location: England
Contact:

Re: [RFC|Accepted] Coding Guideline Modifications

Post by callumacrae » Fri Apr 20, 2012 6:36 pm

Oh. +1 to that :-D
Made by developers, for developers!
My blog

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

Re: [RFC|Accepted] Coding Guideline Modifications

Post by naderman » Sun Apr 22, 2012 9:11 am

I definitely prefer that style for javascript as well. So I would agree to changing coding guidelines to state that in Javascript opening braces go on the same line separated with a space.

User avatar
callumacrae
Infrastructure Team
Infrastructure Team
Posts: 1046
Joined: Tue Apr 27, 2010 9:37 am
Location: England
Contact:

Re: [RFC|Accepted] Coding Guideline Modifications

Post by callumacrae » Sun Apr 22, 2012 12:19 pm

Can we have camel-cap var and function names for JS, too? While PHP doesn't really have a standard, all the built in JS libraries use camel-caps, so it looks a bit weird to have anything else.
Made by developers, for developers!
My blog

User avatar
brunoais
Registered User
Posts: 958
Joined: Fri Dec 18, 2009 3:55 pm

Re: [RFC] Javascript Coding Style

Post by brunoais » Tue Apr 24, 2012 6:36 pm

^
+1

User avatar
hanakin
Infrastructure Team
Infrastructure Team
Posts: 790
Joined: Sat Dec 25, 2010 9:02 pm
Contact:

Re: [RFC] Javascript Coding Style

Post by hanakin » Sun Apr 29, 2012 5:41 am

+1

Post Reply