'Bob Nystrom' via Dart Misc
2015-06-19 21:21:06 UTC
Greetings, Dartisans!
I'll just get the call to action out of the way first:
*I've made a ton of improvements to the formatter, but I'd like you to try
it out before I ship it in the next version of the SDK. To give it a shot:*
1. Install the release candidate of the Dart formatter:
$ pub global activate *dart_style 0.2.0-rc.1*
2. Run it on some of your code:
$ pub global run *dart_style:format* *<file* *paths...>*
3. Let me know <https://github.com/dart-lang/dart_style/issues> if you
see anything busted in the output, crashes, stalls, etc.
The brave/foolhardy are also welcome to start using this version for real.
If you decide to do that, make sure everyone on your team does too.
Assuming all goes well, I'll kick out a real 0.2.0 release and bring that
into the SDK soon. I've run the new formatter on lots of code, but I'd
still like to get more validation before I foist it onto the world.
*Background*
I've been deep in a dark code hole for the past several months hacking away
on the formatter (dartfmt). Seriously, look at these commits
<https://github.com/dart-lang/dart_style/graphs/commit-activity>. The
formatter had some fundamental limitations that made it impossible to fix
the bugs that were piling up. It took damn near a whole rewrite, but those
limitations have been removed and the formatter now has a much more
sophisticated splitting engine.
Once I got that working, I could finally fix some old bugs that had been
driving me crazy. After that, I plowed through a bunch more bugs
<https://github.com/dart-lang/dart_style/issues?q=is%3Aissue+is%3Aclosed>.
*Despite all of that, most of your code will look the same. This is about
improving the output in the 10% of the cases where it was doing a bad job.
The other 90% is the same.*
There are too many fixes to count, but here's some big ones:
Long argument and parameter lists
The old formatter would just keep packing in arguments as tightly as it
could, leading to an unreadable blob of text. Now, if the list doesn't fit
in two lines, each argument or parameter gets moved to its own line.
Old:
analysisServer = new AnalysisServer(serverChannel, resourceProvider,
new OptimizingPubPackageMapProvider(resourceProvider, defaultSdk),
index, serverPlugin, analysisServerOptions, defaultSdk,
instrumentationService, rethrowExceptions: false);
New:
analysisServer = new AnalysisServer(
serverChannel,
resourceProvider,
new OptimizingPubPackageMapProvider(resourceProvider, defaultSdk),
index,
serverPlugin,
analysisServerOptions,
defaultSdk,
instrumentationService,
rethrowExceptions: false);
Complex nested function calls
It does a better job of splitting outer argument lists to highlight the
call structure:
Old:
Element element = new Element(ElementKind.ENUM_CONSTANT, name, Element
.makeFlags(
isPrivate: Identifier.isPrivateName(name),
isDeprecated: _isDeprecated(node)),
location: _getLocationNode(nameNode));
New:
Element element = new Element(
ElementKind.ENUM_CONSTANT,
name,
Element.makeFlags(
isPrivate: Identifier.isPrivateName(name),
isDeprecated: _isDeprecated(node)),
location: _getLocationNode(nameNode));
Big collection literals
Often, you're creating a bunch of data inside a large collection literal,
something complex enough that you have line comments inside explaining its
structure. Now, the formatter will preserve your newlines inside that to
maintain the structure:
Old:
class Foo {
/**
* Basic one-byte 608 CC char set, mostly ASCII.
* Indexed by (char-0x20).
*/
static const List<int> ccUtfTable0 = const <int>[
0x20,
0x21,
0x22,
0x23,
0x24,
0x25,
0x26,
0x27, // ! " # $ % & '
0x28,
0x29, // ( )
0xE1, // 2A: 225 'á' "Latin small letter A with acute"
0x2b,
0x2c,
0x2d,
0x2e,
0x2f, // + , - . /
0x30,
0x31,
0x32,
0x33,
0x34,
0x35,
0x36,
0x37, // 0 1 2 3 4 5 6 7
0x38,
0x39,
0x3a,
0x3b,
0x3c,
0x3d,
0x3e,
0x3f, // 8 9 : ; < = > ?
0x40,
0x41,
0x42,
0x43,
0x44,
0x45,
0x46,
0x47, // @ A B C D E F G
0x48,
0x49,
0x4a,
0x4b,
0x4c,
0x4d,
0x4e,
0x4f, // H I J K L M N O
0x50,
0x51,
0x52,
0x53,
0x54,
0x55,
0x56,
0x57, // P Q R S T U V W
];
}
(Ugh, I know, right?)
New:
class Foo {
/**
* Basic one-byte 608 CC char set, mostly ASCII.
* Indexed by (char-0x20).
*/
static const List<int> ccUtfTable0 = const <int>[
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, // ! " # $ % & '
0x28, 0x29, // ( )
0xE1, // 2A: 225 'á' "Latin small letter A with acute"
0x2b, 0x2c, 0x2d, 0x2e, 0x2f, // + , - . /
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, // 0 1 2 3 4 5 6 7
0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, // 8 9 : ; < = > ?
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, // @ A B C D E F G
0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, // H I J K L M N O
0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, // P Q R S T U V W
];
}
Nested functions and collections
The indentation rules for functions and collections are more sophisticated
and allow them to indent like expressions in contexts where that produces a
more readable result. It's hard to track down a good before/after, but in
big nested expressions full of higher-order functions, you'll often see
better results.
There's tons of other little fixes too, so let me know how it goes.
Cheers!
- bob
I'll just get the call to action out of the way first:
*I've made a ton of improvements to the formatter, but I'd like you to try
it out before I ship it in the next version of the SDK. To give it a shot:*
1. Install the release candidate of the Dart formatter:
$ pub global activate *dart_style 0.2.0-rc.1*
2. Run it on some of your code:
$ pub global run *dart_style:format* *<file* *paths...>*
3. Let me know <https://github.com/dart-lang/dart_style/issues> if you
see anything busted in the output, crashes, stalls, etc.
The brave/foolhardy are also welcome to start using this version for real.
If you decide to do that, make sure everyone on your team does too.
Assuming all goes well, I'll kick out a real 0.2.0 release and bring that
into the SDK soon. I've run the new formatter on lots of code, but I'd
still like to get more validation before I foist it onto the world.
*Background*
I've been deep in a dark code hole for the past several months hacking away
on the formatter (dartfmt). Seriously, look at these commits
<https://github.com/dart-lang/dart_style/graphs/commit-activity>. The
formatter had some fundamental limitations that made it impossible to fix
the bugs that were piling up. It took damn near a whole rewrite, but those
limitations have been removed and the formatter now has a much more
sophisticated splitting engine.
Once I got that working, I could finally fix some old bugs that had been
driving me crazy. After that, I plowed through a bunch more bugs
<https://github.com/dart-lang/dart_style/issues?q=is%3Aissue+is%3Aclosed>.
*Despite all of that, most of your code will look the same. This is about
improving the output in the 10% of the cases where it was doing a bad job.
The other 90% is the same.*
There are too many fixes to count, but here's some big ones:
Long argument and parameter lists
The old formatter would just keep packing in arguments as tightly as it
could, leading to an unreadable blob of text. Now, if the list doesn't fit
in two lines, each argument or parameter gets moved to its own line.
Old:
analysisServer = new AnalysisServer(serverChannel, resourceProvider,
new OptimizingPubPackageMapProvider(resourceProvider, defaultSdk),
index, serverPlugin, analysisServerOptions, defaultSdk,
instrumentationService, rethrowExceptions: false);
New:
analysisServer = new AnalysisServer(
serverChannel,
resourceProvider,
new OptimizingPubPackageMapProvider(resourceProvider, defaultSdk),
index,
serverPlugin,
analysisServerOptions,
defaultSdk,
instrumentationService,
rethrowExceptions: false);
Complex nested function calls
It does a better job of splitting outer argument lists to highlight the
call structure:
Old:
Element element = new Element(ElementKind.ENUM_CONSTANT, name, Element
.makeFlags(
isPrivate: Identifier.isPrivateName(name),
isDeprecated: _isDeprecated(node)),
location: _getLocationNode(nameNode));
New:
Element element = new Element(
ElementKind.ENUM_CONSTANT,
name,
Element.makeFlags(
isPrivate: Identifier.isPrivateName(name),
isDeprecated: _isDeprecated(node)),
location: _getLocationNode(nameNode));
Big collection literals
Often, you're creating a bunch of data inside a large collection literal,
something complex enough that you have line comments inside explaining its
structure. Now, the formatter will preserve your newlines inside that to
maintain the structure:
Old:
class Foo {
/**
* Basic one-byte 608 CC char set, mostly ASCII.
* Indexed by (char-0x20).
*/
static const List<int> ccUtfTable0 = const <int>[
0x20,
0x21,
0x22,
0x23,
0x24,
0x25,
0x26,
0x27, // ! " # $ % & '
0x28,
0x29, // ( )
0xE1, // 2A: 225 'á' "Latin small letter A with acute"
0x2b,
0x2c,
0x2d,
0x2e,
0x2f, // + , - . /
0x30,
0x31,
0x32,
0x33,
0x34,
0x35,
0x36,
0x37, // 0 1 2 3 4 5 6 7
0x38,
0x39,
0x3a,
0x3b,
0x3c,
0x3d,
0x3e,
0x3f, // 8 9 : ; < = > ?
0x40,
0x41,
0x42,
0x43,
0x44,
0x45,
0x46,
0x47, // @ A B C D E F G
0x48,
0x49,
0x4a,
0x4b,
0x4c,
0x4d,
0x4e,
0x4f, // H I J K L M N O
0x50,
0x51,
0x52,
0x53,
0x54,
0x55,
0x56,
0x57, // P Q R S T U V W
];
}
(Ugh, I know, right?)
New:
class Foo {
/**
* Basic one-byte 608 CC char set, mostly ASCII.
* Indexed by (char-0x20).
*/
static const List<int> ccUtfTable0 = const <int>[
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, // ! " # $ % & '
0x28, 0x29, // ( )
0xE1, // 2A: 225 'á' "Latin small letter A with acute"
0x2b, 0x2c, 0x2d, 0x2e, 0x2f, // + , - . /
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, // 0 1 2 3 4 5 6 7
0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, // 8 9 : ; < = > ?
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, // @ A B C D E F G
0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, // H I J K L M N O
0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, // P Q R S T U V W
];
}
Nested functions and collections
The indentation rules for functions and collections are more sophisticated
and allow them to indent like expressions in contexts where that produces a
more readable result. It's hard to track down a good before/after, but in
big nested expressions full of higher-order functions, you'll often see
better results.
There's tons of other little fixes too, so let me know how it goes.
Cheers!
- bob
--
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
To unsubscribe from this group and stop receiving emails from it, send an email to misc+***@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
To unsubscribe from this group and stop receiving emails from it, send an email to misc+***@dartlang.org.