[RFC] Coding guidelines - Comma on left

These RFCs were either rejected or have been replaced by an alternative proposal. They will not be included in phpBB.
drathbun
Registered User
Posts: 72
Joined: Wed Feb 15, 2006 6:40 pm
Location: Texas
Contact:

[RFC] Coding guidelines - Comma on left

Post by drathbun » Mon Jun 11, 2012 3:41 pm

Regarding comma left or right as mentioned here

bantu wrote:
drathbun wrote:Comma on the left allows one to comment out a line of code without rewriting it.
In general this is not the case since you can not comment out the first line. The JavaScript notation supports spare comma on the left as much as it supports spare comma on the right: Not at all.

Furthermore, current coding guidelines apply and should be followed. If you think comma on the left is a useful change, please post in the coding guidelines topic instead.
Of course you cannot comment out the first line, that's true no matter where a comma exists. But you can comment out lines within the middle of a function call or sql script if the comma is on the left.

For example a SQL statement all on one line (not standard, just for example)

Code: Select all

select a, b, c, d from table1, table2, table3 where join1 and join2 and join3
Same SQL statement formatted better, commas on the right:

Code: Select all

select a,
b,
c,
d
from table1,
table2,
table3
where join1
and join2
and join3
Where are the "and" connectors? On the left. Not like this:

Code: Select all

select a,
b,
c,
d
from table1,
table2,
table3
where join1 and
join2 and
join3
Comma on the left

Code: Select all

select a
, b
, c
, d
from table1
,table2
,table3
where join1
and join2
and join3
Now, other than the required SELECT and FROM and WHERE statements, any individual line of code can be commented / removed without editing any other line of code. If a comma or connector (like "and" as mentioned above) is on the right rather than on the left, this is not true.

I realize this is a religious war much like whether { } should be on their own line or not. ;) But I feel that there are specific benefits to having a comma / connector left strategy that apparently were not apparent to the person who responded to my post in the other topic quoted above.
Last edited by drathbun on Mon Jun 11, 2012 4:02 pm, edited 2 times in total.
Sometimes you're the windshield, sometimes you're the bug.

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

Re: [RFC|Accepted] Coding Guideline Modifications

Post by Erik Frèrejean » Mon Jun 11, 2012 3:53 pm

+1

I'm actually starting to utilise this style more and more on private projects. Especially in the "and" case the resulting query is a lot easier to read when just glazing over it.
Available on .com
Support Toolkit developer

User avatar
imkingdavid
Registered User
Posts: 1050
Joined: Thu Jul 30, 2009 12:06 pm

Re: [RFC|Accepted] Coding Guideline Modifications

Post by imkingdavid » Mon Jun 11, 2012 4:40 pm

I like the AND on the left on the new line, but the comma on the left just looks ugly and is more difficult to type.
I do custom MODs. PM for a quote!
View My: MODs | Portfolio
Please do NOT contact for support via PM or email.
Remember, the enemy's gate is down.

drathbun
Registered User
Posts: 72
Joined: Wed Feb 15, 2006 6:40 pm
Location: Texas
Contact:

Re: [RFC|Accepted] Coding Guideline Modifications

Post by drathbun » Mon Jun 11, 2012 6:57 pm

imkingdavid wrote:...and is more difficult to type.
Really? :P That's your argument? , then CR is harder than CR then ,?

It's not a difficult change to get used it. I've written code like this for a long time, it's second nature at this point. But as I already said, I get that it's a style that some folks will like, some folks will not. I use the , to help with the indentation style as well.

Code: Select all

select  col1
,       col2
,       col3
from    tab1
,       tab2
,       tab3
where   join1
and     join2
Sometimes you're the windshield, sometimes you're the bug.

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

Re: [RFC|Accepted] Coding Guideline Modifications

Post by Oleg » Mon Jun 11, 2012 7:04 pm

In my projects I now put trailing commas everywhere in javascript and have a post-processing pass to take them out before deployment.

I find leading punctuation ugly.

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

Re: [RFC|Accepted] Coding Guideline Modifications

Post by callumacrae » Mon Jun 11, 2012 9:14 pm

I also find leading punctuation extremely ugly, -1.
Made by developers, for developers!
My blog

drathbun
Registered User
Posts: 72
Joined: Wed Feb 15, 2006 6:40 pm
Location: Texas
Contact:

Re: [RFC|Accepted] Coding Guideline Modifications

Post by drathbun » Tue Jun 12, 2012 3:32 am

Whatever. :P Ugly or "too hard to type" aren't objections that override the functional advantages in my opinion. That being said, I won't keep beating the horse. I made the suggestion, feel free to discuss or ignore.
Sometimes you're the windshield, sometimes you're the bug.

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

Re: [RFC|Accepted] Coding Guideline Modifications

Post by brunoais » Mon Jun 25, 2012 1:51 pm

I accept the comma on the left in both js and PHP, the AND on the left, etc...
Still we need to make that in a correct way IYKWIM.
We'll need to keep that code formatted and readable.
Something like drathbun's example except you'd use caps for commands (SELECT, FROM, etc...) and functions.
drathbun wrote:

Code: Select all

select  col1
,       col2
,       col3
from    tab1
,       tab2
,       tab3
where   join1
and     join2
I'll choose ±0 if you keep these conditions, -1 if you don't.

Edit:
This comma on the left, it allows you to add something and have git not say that two lines were changed, but... What happens if it's the 1st thing in the list that is removed and not the last one or one in the middle? We get to the same story, don't we? Comma on the left is better for adding, comma on the right is better for removing. It would just be better if there was a way to have the extra comma on the right without any complaints by the system....

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

Re: [RFC|Accepted] Coding Guideline Modifications

Post by callumacrae » Mon Jun 25, 2012 2:14 pm

brunoais wrote: This comma on the left, it allows you to add something and have git not say that two lines were changed, but... What happens if it's the 1st thing in the list that is removed and not the last one or one in the middle? We get to the same story, don't we? Comma on the left is better for adding, comma on the right is better for removing. It would just be better if there was a way to have the extra comma on the right without any complaints by the system....
The general idea is that you have the semi-colon on its own line:

Code: Select all

var a = 'b',
    , b = 'c'
    , c = 'd'
    , d = 'e'
    , e = 'f'
    ;
It looks horrific. -1 to sacrificing clean and pretty code for nicer diffs.
Made by developers, for developers!
My blog

User avatar
imkingdavid
Registered User
Posts: 1050
Joined: Thu Jul 30, 2009 12:06 pm

Re: [RFC|Accepted] Coding Guideline Modifications

Post by imkingdavid » Mon Jun 25, 2012 2:23 pm

brunoais wrote:Edit:
This comma on the left, it allows you to add something and have git not say that two lines were changed, but... What happens if it's the 1st thing in the list that is removed and not the last one or one in the middle? We get to the same story, don't we? Comma on the left is better for adding, comma on the right is better for removing. It would just be better if there was a way to have the extra comma on the right without any complaints by the system....
Exactly. Except in the case of PHP arrays, in which we can have trailing commas, we are going to have that change show up in Git in one case or another, whether we choose to have commas on the left or right.

I do not see the point in going through all the trouble to change this.
I do custom MODs. PM for a quote!
View My: MODs | Portfolio
Please do NOT contact for support via PM or email.
Remember, the enemy's gate is down.

Post Reply