Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple assignments on a single line. #65

Open
nubs opened this issue Jun 18, 2013 · 14 comments
Open

Multiple assignments on a single line. #65

nubs opened this issue Jun 18, 2013 · 14 comments
Labels

Comments

@nubs
Copy link
Contributor

nubs commented Jun 18, 2013

Our standard currently allows code like this:

$foo = $bar = null;

Do we want to continue allowing that?

👍 if you like multiple assignments in one statement
👎 if you don't

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

👍 : 3
👎 : 3

@nubs
Copy link
Contributor Author

nubs commented Jun 18, 2013

👎

1 similar comment
@chrisryan
Copy link
Contributor

👎

@yonderblue
Copy link
Contributor

👍

@RAGoody
Copy link

RAGoody commented Jun 18, 2013

downvote.

On Tue, Jun 18, 2013 at 3:04 PM, Jonathan Gaillard <[email protected]

wrote:

[image: 👍]


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

@jwogan5
Copy link

jwogan5 commented Jun 18, 2013

👍

@rjh427
Copy link

rjh427 commented Jun 19, 2013

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.

🎱

@kkenyon
Copy link

kkenyon commented Jun 19, 2013

👍

@c-cataldo
Copy link

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
[email protected]:

[image: 👍]


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

@yonderblue
Copy link
Contributor

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
Copy link
Contributor

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

@nubs
Copy link
Contributor Author

nubs commented Jun 19, 2013

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
Copy link

RAGoody commented Jun 19, 2013

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 <[email protected]

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
Copy link

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

On Wed, Jun 19, 2013 at 10:11 AM, RAGoody [email protected] 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 <
[email protected]

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
Copy link
Contributor Author

nubs commented Jun 19, 2013

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants