traderinteractive / dws-coding-standard

DWS Coding Standard
MIT License
8 stars 11 forks source link

Multiple assignments on a single line. #65

Open nubs opened 11 years ago

nubs commented 11 years ago

Our standard currently allows code like this:

$foo = $bar = null;

Do we want to continue allowing that?

:+1: if you like multiple assignments in one statement :-1: if you don't

@dominionenterprises/dws-arch, @dominionenterprises/tol-rec-dev, @dominionenterprises/tol-industrial-dev feel free to leave your preference.

:+1: : 3 :-1: : 3

nubs commented 11 years ago

:-1:

chrisryan commented 11 years ago

:-1:

yonderblue commented 11 years ago

:thumbsup:

RAGoody commented 11 years ago

downvote.

On Tue, Jun 18, 2013 at 3:04 PM, Jonathan Gaillard <notifications@github.com

wrote:

[image: :thumbsup:]

— Reply to this email directly or view it on GitHubhttps://github.com/dominionenterprises/dws-coding-standard/issues/65#issuecomment-19633433 .

jwogan5 commented 11 years ago

:+1:

rjh427 commented 11 years ago

I can go either way on that sort of multiple assignment. I can see how it can impact readability but sometimes it makes more sense and is far more compact than writing things out the other way, like judicious use of the ternary operator.

What I've seen elsewhere is code like $foo = something; $bar = somethingElse; and all on one line. I believe that is currently a coding standards violation, as it should be.

:8ball:

kkenyon commented 11 years ago

:thumbsup:

c-cataldo commented 11 years ago

Don't care one way or the other. Does anybody want to make a case for one way over the other?

On Wed, Jun 19, 2013 at 9:16 AM, Katherine Kenyon notifications@github.comwrote:

[image: :thumbsup:]

— Reply to this email directly or view it on GitHubhttps://github.com/dominionenterprises/dws-coding-standard/issues/65#issuecomment-19682923 .

yonderblue commented 11 years ago

as evident with great languages like golang, putting a standard in that at least has some majority favor and is enforced (by the sniff) leads to much faster readability, less squabble, better search opportunities etc etc. in the long run. really people can get used to whatever given a little time.. but its more important some standard goes in

yonderblue commented 11 years ago

of course I will post fix in saying this or course isn't priority over business logic

nubs commented 11 years ago

The main reason for doing multiple assignments at once is conciseness as it allows you to initialize a bunch of variables to the same value all at once.

The main reason against it is that it makes it harder to find the variable initialization by scanning the code because some of the variables aren't being assigned at the beginning of their line.

RAGoody commented 11 years ago

My response follows on Jonathan's :

I'm pretty sure 99% of programmers are most used to multiple line variable assignments. A smaller percentage are familiar with/used to single line assignments. It's how most people are taught. It's how most example code you find is written. (which I think is indicative of it being simpler to understand)

Therefore I lean towards what is easiest to read/maintain & for new hires to adapt to.

On Wed, Jun 19, 2013 at 9:49 AM, Jonathan Gaillard <notifications@github.com

wrote:

of course I will post fix in saying this or course isn't priority over business logic

— Reply to this email directly or view it on GitHubhttps://github.com/dominionenterprises/dws-coding-standard/issues/65#issuecomment-19684906 .

c-cataldo commented 11 years ago

Ok, I'm on board with that line of thinking.

On Wed, Jun 19, 2013 at 10:11 AM, RAGoody notifications@github.com wrote:

My response follows on Jonathan's :

I'm pretty sure 99% of programmers are most used to multiple line variable assignments. A smaller percentage are familiar with/used to single line assignments. It's how most people are taught. It's how most example code you find is written. (which I think is indicative of it being simpler to understand)

Therefore I lean towards what is easiest to read/maintain & for new hires to adapt to.

On Wed, Jun 19, 2013 at 9:49 AM, Jonathan Gaillard < notifications@github.com

wrote:

of course I will post fix in saying this or course isn't priority over business logic

— Reply to this email directly or view it on GitHub< https://github.com/dominionenterprises/dws-coding-standard/issues/65#issuecomment-19684906>

.

— Reply to this email directly or view it on GitHubhttps://github.com/dominionenterprises/dws-coding-standard/issues/65#issuecomment-19686309 .

nubs commented 11 years ago

@RAGoody, it depends. In languages where you have to declare your variables (especially when doing so at the top of functions), you very often see multiple initializations at once to different values. The multiple assignments in a line has come from that:

// C/C++
void main()
{
    int x=5, y=10;
    //...
}
// Javascript
function foo() {
    var x=5, y=10;
    // ...
}

That being said, I don't know that I agree with that standard even in those languages.