Skip to content

Dart formatter removes significant whitespace in expressions (WONTFIX) #530

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

Closed
Hixie opened this issue Aug 24, 2016 · 4 comments
Closed

Comments

@Hixie
Copy link

Hixie commented Aug 24, 2016

This expression from Flutter's physics library is flattened by the formatter, which harms readability and would make the code much harder to understand and debug:

    return      power * (_c2 * _w * cosine - _c1 * _w * sine) +
           _r * power * (_c2 *      sine   + _c1 *      cosine);
@Hixie
Copy link
Author

Hixie commented Aug 24, 2016

If there was an unobtrusive way to indicate to the formatter that the line should be left verbatim, that would be sufficient here. Maybe something simple like an empty trailing comment?:

    return      power * (_c2 * _w * cosine - _c1 * _w * sine) +    //
           _r * power * (_c2 *      sine   + _c1 *      cosine);   //

@munificent
Copy link
Member

Sorry, but, no, I don't think dartfmt can help here. :(

The formatter doesn't promise to make every line of your code more readable than a careful hand formatter could produce. A small amount of code, particularly complex expressions like here, will end up losing some visual alignment and a little readability.

In return for those, you are spared from ever having to worry about formatting again.

@Hixie
Copy link
Author

Hixie commented Aug 29, 2016

Being able to read the code is dramatically more important to me than not having to worry about formatting (especially for a framework that we want people to explore as part of an SDK). It is unfortunate that we are forced to make a choice between entirely hand-formatting or having beautiful code, when there are simple solutions that would get us both highly readable code and mostly automatically formatted code. Do you have any suggestions for how we could get auto-formatting yet maintain the higher standard of readability, if dartfmt isn't the answer?

@munificent
Copy link
Member

Being able to read the code is dramatically more important to me than not having to worry about formatting

I would claim that dartfmt's output is still quite readable, it's just not as beautiful as a human could produce in all circumstances.

It is unfortunate that we are forced to make a choice between entirely hand-formatting or having beautiful code, when there are simple solutions that would get us both highly readable code and mostly automatically formatted code.

It's the "mostly" part that's the real trade-off. The goal of dartfmt is to take humans out of the business of hand-tuning whitespace. Our belief is that giving humans control over it isn't a positive value proposition. Yes, they can do a better job in some cases. But they do a worse job in many others—we make lots of mistakes. And it means formatting becomes part of code reviews, etc.

There are a small number of people who care so deeply about readability that they will consistently hand-format code better than dartfmt would. But if you look at the ecosystem as a whole, hand-formatting just isn't a good use of most people's time. dartfmt does as good of a job as them, if not better, and it saves them a ton of effort.

Do you have any suggestions for how we could get auto-formatting yet maintain the higher standard of readability, if dartfmt isn't the answer?

If dartfmt isn't the right tool for you goals, I'm afraid I'm not the right person to ask. What you're looking for isn't unreasonable—it's how tools like clang-format work, I think—it's just a different tool from the one it's my job to maintain. :-/

(For what it's worth, I do think dartfmt's approach to formatting is a better one for the Dart ecosystem than a tool that helped you format but also let you do hand-formatting. But I'm not trying to force you to buy into that idea.)

@Hixie Hixie changed the title Dart formatter removes significant whitespace in expressions Dart formatter removes significant whitespace in expressions (WONTFIX) Sep 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants