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

Add guidelines on multiple assignments in a single line #80

Open
raphaelsaavedra opened this issue Nov 17, 2020 · 5 comments
Open

Add guidelines on multiple assignments in a single line #80

raphaelsaavedra opened this issue Nov 17, 2020 · 5 comments
Labels
documentation Improvements or additions to documentation good first issue Good for newcomers

Comments

@raphaelsaavedra
Copy link
Contributor

Sometimes one might want to do multiple assignments in a single line to reduce number of lines of code, e.g.

Pmin, Pmax = get_pmin(fnm.system), get_pmax(fnm.system)

If this is considered bad style by us, we should probably add a comment about this in the docs.

@raphaelsaavedra raphaelsaavedra added the documentation Improvements or additions to documentation label Nov 17, 2020
@omus
Copy link
Contributor

omus commented Dec 11, 2020

I think multiple assignments from a single call is okay (unpacking):

a, b, c = f()

but multiple assignments from multiple calls should probably be avoided.

@fchorney
Copy link
Contributor

I agree with omus.

@nickrobinson251 nickrobinson251 added the good first issue Good for newcomers label Nov 30, 2021
@mcabbott
Copy link
Member

What about the following pattern:

a, b, c = if cond(x)
    alpha, beta, gamma
else
    nothing, f(beta), g(gamma)
end

IIRC there are cases where one assignment outside an if statement infers better than separate assignments inside it.

@oxinabox
Copy link
Member

That case seems beyond the scope of this issue.
Since this is about multiple assignments on a single line."
I agree that for blocks it can be occasionally useful.

@oxinabox
Copy link
Member

the reason i don't like it is for:
a, b = c(), d()
the reading order I end up having is either: a, c, b, d or c, a, d, b.
Because I want to know what is assigned to what.
both of which are easier with

a = c()
b = d()

I guess another way to describe this rule would be "Do not create tuples just to unpack them on the same line" ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

6 participants