--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+uns...@dartlang.org.
If you had a big code base, and were many people to work on it, I wouldn't mind using another line width if that'd help you.To do so, you can pass an argument to dartfmt to specify the line length.ie:dartfmt -l 120
Also, offtopic a bit -- you should take a look at the http package, and also the usage of async/await (but I'm sure you know about the last one)
--
Up the line-length to 120 and I'll probably use it, 80 is fine for normal OO code, but when you start in-lining some lambdas, you overrun the 80 character limit very quickly.
In the above screenshots, the "unformatted" code actually reads easier.
I have some cases - parts of files - that I'd prefer to be excluded from formatting. Maybe a tag could be invented? Eg extending triple slash...
/// #*
Ignored code for formatting
..
/// *#
That could be extended to set line widths too, maybe?
Otherwise, for me, it just works fine. I haven't studied it much (maybe the above is already available!).
S
--
I'm wondering if people are actually using it? If general consensus is yes, I might make an effort, but otherwise I'm thinking of just ditching it and going with tabs.
especially the method at the bottom (I don't think it'd look so bad with string.format, but it looks horrible like this).
If it just didn't remove linebreaks I'd inserted before dots, I'd probably be really happy with it (I'd set a longer line length, then not have the unwrapping)!
I have some cases - parts of files - that I'd prefer to be excluded from formatting. Maybe a tag could be invented? Eg extending triple slash...
/// #*
Ignored code for formatting
..
/// *#
blah.dosomething.dosomethingElse.uppercase.sort.filtershould never become:blah.dosomething.dosomethingElse
blah.doSomething().doSomethingElse().uppercase.sorted.filter(() => stuff > whatever);
I use it from my Atom editor. It automatically formats the code just before saving it. But I would change some things. I have always used the PEAR's coding standards:
It would be nice adopting that format. But it is better than using nothing.
especially the method at the bottom (I don't think it'd look so bad with string.format, but it looks horrible like this).I think it would look a little better if you weren't using ".." for the sort() call. If you don't want it to be one line, then going out of your way to make it one statement is a little odd.
I do prefer the 80 column limit. It causes some extra wrapping, but it means I don't have to awkwardly scroll horizontally to see all of the code like I have to do right now with your screenshot in gmail. :)
If it just didn't remove linebreaks I'd inserted before dots, I'd probably be really happy with it (I'd set a longer line length, then not have the unwrapping)!Preserving some of your hand formatting, but not all of it, interferes with a lot of the goals of the formatter.
The formatter is designed to do a good job on real-world code. You can always make non-idiomatic code that gets formatted weird because the formatter isn't tuned for that. If you were to make this example a little more realistic, like:blah.doSomething().doSomethingElse().uppercase.sorted.filter(() => stuff > whatever);Then you will see it also formats it more like you prefer.
especially the method at the bottom (I don't think it'd look so bad with string.format, but it looks horrible like this).I think it would look a little better if you weren't using ".." for the sort() call. If you don't want it to be one line, then going out of your way to make it one statement is a little odd.I didn't go out of my way to make it one statement, it just felt more natural (otherwise I'd have loads of variables only being used on the next line, which seems rather noisy).I'm a total Dart noob though, so don't for a minute think this code is ideal. I'd be really interested to know how you'd write/format it though! A copy of the file is here:
I do prefer the 80 column limit. It causes some extra wrapping, but it means I don't have to awkwardly scroll horizontally to see all of the code like I have to do right now with your screenshot in gmail. :)To be fair, that's two screens side-by-side! :P
I've just got an ultrawide monitor (2660x1080) and I have all this width not being used...
Even with two VS Code windows open (both with the explorer view down the side) 80 characters takes up hardly any of the screen.I don't think constraining the width is a bad idea, it just feels like 80 is too short (and it feels like indenting with 2 spaces, which I think is also insane, was done because of this width) :(
The formatter is designed to do a good job on real-world code. You can always make non-idiomatic code that gets formatted weird because the formatter isn't tuned for that. If you were to make this example a little more realistic, like:blah.doSomething().doSomethingElse().uppercase.sorted.filter(() => stuff > whatever);Then you will see it also formats it more like you prefer.But presumably that only doesn't get unwrapped because the whole thing is too long?
It seems weird that you could write two identical chunks like that, one 81 chars, one 79 and they would format very differently.
I presume the rules on the decisions the formatter uses aren't really documented other than in the source?
If it were my code, I'd do:String toQueryString(Map<String, String> data) {var items = data.keys.map((k) => "$k=${encode(data[k])}").toList();items.sort();return items.join("&");}
To be fair, that's two screens side-by-side! :PRight, but that's a typical use case when you're doing code reviews, looking at diffs, etc.
Many users (including me, for what it's worth) do almost all of their work on a laptop screen.
Readability of text generally goes down when lines go above a certain length. The wider the line, the longer it takes your eye to track back to the beginning of the next line, and the greater chance of making mistakes and skipping or double-reading a line. That's why newspapers use several relatively columns of text on their big wide sheets of paper.
I don't know where the 2 space thing comes from, but it's used in languages at Google that don't have the 80 column limit. We just followed other Google language styles that all use 2 spaces. It seems like most of the open source ecosystem is going in that direction too.
Alas, no, though I have an issue to do that. I did write up how the formatter applies its rules, though. It's pretty complex.
Iterable<Metadata/*=T*/> classMetadataQueryAll/*<T extends Metadata>*/(ClassMetadata clazz, MetadataMatchFunction matcher, {bool includeFields: defaultInclude, bool includeConstructors: defaultInclude, bool includeMethods: defaultInclude}) => _expandClassMetadata/*<T>*/( clazz, includeFields, includeConstructors, includeMethods ).where(matcher);
Iterable<Metadata/*=T*/ > classMetadataQueryAll/*<T extends Metadata>*/( ClassMetadata clazz, MetadataMatchFunction matcher, {bool includeFields: defaultInclude, bool includeConstructors: defaultInclude, bool includeMethods: defaultInclude}) => _expandClassMetadata/*<T>*/( clazz, includeFields, includeConstructors, includeMethods) .where(matcher);
You could probably take any code snippet, think long and hard about its artful indentation, and create a more delightful organization of code than dartfmt would produce... to you. The value to me is that dartfmt is completely automated, deterministic, and the results are pretty good for most people (something humans can also have a hard time with). Consistent formatting also reduces merge conflicts and diff distractions. I think the practical benefits make the occasional less than ideal formatting more than forgivable. The time and stress savings make dartfmt a joy to use if you (and your team) are able to let go a little on what you may prefer.
80 chars on modern screens seems ridiculous but if I want to read a file on GitHub directly without checking the code out locally to open it in my favorite IDE I'm glad the author didn't use longer lines.In my IDE it has the advantage, that I can have 2 or 3 files side-by-side easily.I wouldn't want to contribute to a Dart project that doesn't use dartfmt. It's not always perfect but a single keystroke and it's good enough and consistent across all files of a project and all projects.
Formatting code manually seems like a good way to me to waste time for nothing.
Vote 1: Fascist enforcement of code formatting!!
That said, I've often wondered why we can't customise formatting more for the visible document in our IDEs.. Why can't we set our own formatting rules in the IDE but have the saved file always the dartfmt'd version? Want braces in the correct places? Fine! Want to indent (correctly ;)) with tabs? Want all method/ctor signatures on one line? Fine!I'm not saying there aren't complications; but imagine if dartfmt accepted dynamic rules and the IDE applies one set during load and another during save! =)That's an interesting idea. I guess version comparisons don't work when there are such differences even though they are only white spaces.
--
Usually having customizable formatters, especially at Google-scale, is a recipe for lots of disagreement and differences between projects.At least internally there is of course lots of personal preferences on how they wish formatting works, but we've generally agreed having 'dartfmt' as a standard 1-way to do formatting makes code reviews simpler (no personal preferences enforced) and allows things like generated code to share the same formatting.
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to a topic in the Google Groups "Dart Misc" group.
To unsubscribe from this topic, visit https://groups.google.com/a/dartlang.org/d/topic/misc/P56eCKMiP7Q/unsubscribe.
To unsubscribe from this group and all its topics, send an email to misc+uns...@dartlang.org.
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to a topic in the Google Groups "Dart Misc" group.
To unsubscribe from this topic, visit https://groups.google.com/a/dartlang.org/d/topic/misc/P56eCKMiP7Q/unsubscribe.
To unsubscribe from this group and all its topics, send an email to misc+uns...@dartlang.org.
> IDE show a personally customised representation to you that is disconnected from what's on the disk :-)
That sounds a bit like personally configurable tab indent size and we know how that ended ;-)
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+uns...@dartlang.org.