[RFC] Coding guidelines: var keyword in js per line

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.
Post Reply
User avatar
callumacrae
Former Team Member
Posts: 1046
Joined: Tue Apr 27, 2010 9:37 am
Location: England
Contact:

Re: [RFC] Coding guidelines: var keyword in js per line

Post by callumacrae »

Okay, a better example:

What you're suggesting is the equivalent of suggesting that we have one global statement per variable in PHP. Nicer diffs, but not too logical.
Made by developers, for developers!
My blog

User avatar
Erik Frèrejean
Registered User
Posts: 207
Joined: Thu Oct 25, 2007 2:25 pm
Location: surfnet
Contact:

Re: [RFC] Coding guidelines: var keyword in js per line

Post by Erik Frèrejean »

Why don't you give a real argument against this proposal rather then "examples" which either don't have anything to do with the subject or that reflect on something that is already phased out?
As far as I'm concerned there is really no hurt, you just have to type 3 additional characters rather than 3 spaces to keep things aligned.
Available on .com
Support Toolkit developer

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

Re: [RFC] Coding guidelines: var keyword in js per line

Post by callumacrae »

I don't see any advantages, and it isn't at all DRY.
Made by developers, for developers!
My blog

wGEric
Registered User
Posts: 521
Joined: Wed Jun 11, 2003 2:07 am
Contact:

Re: [RFC] Coding guidelines: var keyword in js per line

Post by wGEric »

Erik Frèrejean wrote:Why don't you give a real argument against this proposal rather then "examples" which either don't have anything to do with the subject or that reflect on something that is already phased out?
As far as I'm concerned there is really no hurt, you just have to type 3 additional characters rather than 3 spaces to keep things aligned.
There isn't really an argument. Changing the style of your code so that the diffs are pretty isn't a good argument. If you minify the Javascript it will probably combine all of them into one var statement so it doesn't matter there. You are using strict mode so global variables aren't an issue. It all comes down to what people prefer.

Code: Select all

var a;
var b;
var c;
var d;
Or

Code: Select all

var a,
    b,
    c,
    d;
I prefer one var because it is quicker/easier to type. Really you shouldn't be adding 3 spaces since phpBB uses tabs (did this change?). Multiple var statements add clutter that doesn't really add anything to the code.
Eric

User avatar
Arty
Former Team Member
Posts: 985
Joined: Wed Mar 06, 2002 2:36 pm
Location: Mars
Contact:

Re: [RFC] Coding guidelines: var keyword in js per line

Post by Arty »

-1

This RFC is an equivalent of putting each global declaration in PHP code on its own line, like

Code: Select all

global $db, $user, $session, $whatever;
being replaced with

Code: Select all

global $db;
global $user;
global $session;
global $whatever;
for sake of cleaner diffs.

Does that PHP code make sense? No, it doesn't. Nether does this RFC.

User avatar
MichaelC
Development Team
Development Team
Posts: 889
Joined: Thu Jan 28, 2010 6:29 pm

Re: [RFC] Coding guidelines: var keyword in js per line

Post by MichaelC »

Arty wrote:-1

This RFC is an equivalent of putting each global declaration in PHP code on its own line, like

Code: Select all

global $db, $user, $session, $whatever;
being replaced with

Code: Select all

global $db;
global $user;
global $session;
global $whatever;
for sake of cleaner diffs.

Does that PHP code make sense? No, it doesn't. Nether does this RFC.
+1
Formerly known as Unknown Bliss
psoTFX wrote: I went with Olympus because as I said to the teams ... "It's been one hell of a hill to climb"
No unsolicited PMs please except for quotes.

Oleg
Posts: 1150
Joined: Tue Feb 23, 2010 2:38 am
Contact:

Re: [RFC] Coding guidelines: var keyword in js per line

Post by Oleg »

Arty wrote:-1

This RFC is an equivalent of putting each global declaration in PHP code on its own line, like

Code: Select all

global $db, $user, $session, $whatever;
being replaced with

Code: Select all

global $db;
global $user;
global $session;
global $whatever;
for sake of cleaner diffs.

Does that PHP code make sense? No, it doesn't. Nether does this RFC.
You completely misunderstood the proposal. Please read it carefully. wGEric correctly understood it:
wGEric wrote:It all comes down to what people prefer.

Code: Select all

var a;
var b;
var c;
var d;
Or

Code: Select all

var a,
    b,
    c,
    d;

User avatar
Arty
Former Team Member
Posts: 985
Joined: Wed Mar 06, 2002 2:36 pm
Location: Mars
Contact:

Re: [RFC] Coding guidelines: var keyword in js per line

Post by Arty »

Oleg wrote:You completely misunderstood the proposal. Please read it carefully.
I don't think I did. In JavaScript it is usual practice to declare each variable on its own line, so adding "var" to each line is equivalent to what I wrote.

That is unless you wanted to suggest something else from that article you linked to. In that case please do elaborate, not just link to long article.

User avatar
bantu
3.0 Release Manager
3.0 Release Manager
Posts: 557
Joined: Thu Sep 07, 2006 11:22 am
Location: Karlsruhe, Germany
Contact:

Re: [RFC] Coding guidelines: var keyword in js per line

Post by bantu »

Oleg wrote:Each line in JS that declares variables should have its own var keyword, in order for diffs to not change irrelevant lines.

See also: http://benalman.com/news/2012/05/multip ... avascript/
I support this.

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

Re: [RFC] Coding guidelines: var keyword in js per line

Post by naderman »

callumacrae wrote:Okay, a better example:

What you're suggesting is the equivalent of suggesting that we have one global statement per variable in PHP. Nicer diffs, but not too logical.
Arty wrote:-1

This RFC is an equivalent of putting each global declaration in PHP code on its own line, like

Code: Select all

global $db, $user, $session, $whatever;
being replaced with

Code: Select all

global $db;
global $user;
global $session;
global $whatever;
for sake of cleaner diffs.

Does that PHP code make sense? No, it doesn't. Nether does this RFC.
I would actually be in favour of that. However in new code we are no longer using global variables, and we decided not to rewrite large sections of code in 3.x for coding style reasons, so there's no point in doing that for global variables.

On the subject of this RFC +1

Post Reply