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

Tall style: Put multiple assignments on the same line #1536

Open
nex3 opened this issue Aug 16, 2024 · 1 comment
Open

Tall style: Put multiple assignments on the same line #1536

nex3 opened this issue Aug 16, 2024 · 1 comment

Comments

@nex3
Copy link
Member

nex3 commented Aug 16, 2024

Rather than

void main() {
  DeprecationProcessingLogger deprecationLogger =
      logger = DeprecationProcessingLogger(
        logger ?? Logger.stderr(),
        silenceDeprecations: {...?silenceDeprecations},
        fatalDeprecations: {...?fatalDeprecations},
        futureDeprecations: {...?futureDeprecations},
        limitRepetition: !verbose,
      );
}

I'd prefer

void main() {
  DeprecationProcessingLogger deprecationLogger = logger =
      DeprecationProcessingLogger(
        logger ?? Logger.stderr(),
        silenceDeprecations: {...?silenceDeprecations},
        fatalDeprecations: {...?fatalDeprecations},
        futureDeprecations: {...?futureDeprecations},
        limitRepetition: !verbose,
      );
}

While the AST thinks of the second assignment as an expression, as a user I think of it as an addendum to the LHS, and so I expect it to bind more tightly there than to the value of the assignment.

@lrhn
Copy link
Member

lrhn commented Aug 27, 2024

It feels like there is a kind of expression that has a a header and a body, and it's OK to keep the header on the same line as something else, and move the body to new lines. (Making up terminology on the spot.)

That's what collection literals do:

List<Map<BigType, LongType> longName = <Map<BigType, LongType>[
     element1,
     element2,
];

The expression <Map<...>[....] can be split over multiple lines while keeping the header (<Map<...>>[) on the same line as other context.
It's probably even preferred to split that way, if possible.

This issue is suggesting that the LHS and = of an assignment can be such a header, and that it's preferred to keep it on the same line as something else, if possible.

Another example could be:

var banana = longFunctionName("args", target =
    biggerAssignedExpression(...));

(Although that may just put every argument on its own line.)

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

No branches or pull requests

2 participants