phpBB

Development Discussion Board

phpBB's testing ground of bleeding edge code
Advanced search

[RFC|Merged] Javascript Coding Style

These requests for comments 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.

[RFC|Merged] Javascript Coding Style

Postby _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 !
_hsr
Registered User
 
Posts: 42
Joined: Mon Mar 26, 2012 7:06 am

Re: [RFC|Accepted] Coding Guideline Modifications

Postby 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.
"In JavaScript, there is a beautiful, elegant, highly expressive language that is buried under a steaming pile of good intentions and blunders"
—Douglas Crockford

View my MOD, phpBB Mobile
User avatar
callumacrae
Website Team
Website Team
 
Posts: 881
Joined: Tue Apr 27, 2010 9:37 am
Location: England

Re: [RFC|Accepted] Coding Guideline Modifications

Postby _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 !
_hsr
Registered User
 
Posts: 42
Joined: Mon Mar 26, 2012 7:06 am

Re: [RFC|Accepted] Coding Guideline Modifications

Postby 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.
"In JavaScript, there is a beautiful, elegant, highly expressive language that is buried under a steaming pile of good intentions and blunders"
—Douglas Crockford

View my MOD, phpBB Mobile
User avatar
callumacrae
Website Team
Website Team
 
Posts: 881
Joined: Tue Apr 27, 2010 9:37 am
Location: England

Re: [RFC|Accepted] Coding Guideline Modifications

Postby 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.
www.naderman.de
Move your forum to Forumatic - we'll take care of maintenance & spam
User avatar
naderman
Development Team Leader
Development Team Leader
 
Posts: 1649
Joined: Sun Jan 11, 2004 2:11 am
Location: Karlsruhe, Germany

Re: [RFC|Accepted] Coding Guideline Modifications

Postby callumacrae » Fri Apr 20, 2012 6:36 pm

Oh. +1 to that :-D
"In JavaScript, there is a beautiful, elegant, highly expressive language that is buried under a steaming pile of good intentions and blunders"
—Douglas Crockford

View my MOD, phpBB Mobile
User avatar
callumacrae
Website Team
Website Team
 
Posts: 881
Joined: Tue Apr 27, 2010 9:37 am
Location: England

Re: [RFC|Accepted] Coding Guideline Modifications

Postby 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.
www.naderman.de
Move your forum to Forumatic - we'll take care of maintenance & spam
User avatar
naderman
Development Team Leader
Development Team Leader
 
Posts: 1649
Joined: Sun Jan 11, 2004 2:11 am
Location: Karlsruhe, Germany

Re: [RFC|Accepted] Coding Guideline Modifications

Postby 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.
"In JavaScript, there is a beautiful, elegant, highly expressive language that is buried under a steaming pile of good intentions and blunders"
—Douglas Crockford

View my MOD, phpBB Mobile
User avatar
callumacrae
Website Team
Website Team
 
Posts: 881
Joined: Tue Apr 27, 2010 9:37 am
Location: England

Re: [RFC] Javascript Coding Style

Postby brunoais » Tue Apr 24, 2012 6:36 pm

^
+1
brunoais
Registered User
 
Posts: 626
Joined: Fri Dec 18, 2009 3:55 pm

Re: [RFC] Javascript Coding Style

Postby hanakin » Sun Apr 29, 2012 5:41 am

+1
hanakin
Registered User
 
Posts: 172
Joined: Sat Dec 25, 2010 9:02 pm

Next

Return to [3.1/Ascraeus] Merged RFCs

Who is online

Users browsing this forum: No registered users and 10 guests