Discussion:
[dart-misc] Effective Dart
'Bob Nystrom' via Dart Misc
2015-10-28 22:13:41 UTC
Permalink
Dartisans!

Over the years, a couple of other people on the Dart team and I have
written various docs to help you write better code: the style guide,
"Idiomatic Dart", Kathy's awesome guide on doc comments, and Lasse's
excellent API naming guidelines.

Since then they sort of languished and got out of date (mine in
particular). Also, each had its own structure and organization. Some things
that were in the style guide really belonged elsewhere, etc. It was a mess.

I spent a little time tidying that up and I'm happy to give you Effective
Dart <https://www.dartlang.org/effective-dart/>.

It replaces all of those docs, modernizes them, and has a bunch of new
content. It's my best attempt at distilling what I and the people I work
with know about writing consistent, maintainable Dart code.

I hope it helps you too!

If you find errors or have suggestions, please don't hesitate to file an
issue <https://github.com/dart-lang/www.dartlang.org/issues>.

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.
Joel Trottier-Hébert
2015-10-29 02:50:59 UTC
Permalink
Thanks a lot Bob. I'll read this very carefully. :)
Kudos!

On Wed, Oct 28, 2015 at 6:14 PM 'Bob Nystrom' via Dart Misc <
Post by 'Bob Nystrom' via Dart Misc
Dartisans!
Over the years, a couple of other people on the Dart team and I have
written various docs to help you write better code: the style guide,
"Idiomatic Dart", Kathy's awesome guide on doc comments, and Lasse's
excellent API naming guidelines.
Since then they sort of languished and got out of date (mine in
particular). Also, each had its own structure and organization. Some things
that were in the style guide really belonged elsewhere, etc. It was a mess.
I spent a little time tidying that up and I'm happy to give you Effective
Dart <https://www.dartlang.org/effective-dart/>.
It replaces all of those docs, modernizes them, and has a bunch of new
content. It's my best attempt at distilling what I and the people I work
with know about writing consistent, maintainable Dart code.
I hope it helps you too!
If you find errors or have suggestions, please don't hesitate to file an
issue <https://github.com/dart-lang/www.dartlang.org/issues>.
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
--
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.
Don Olmstead
2015-10-29 06:28:47 UTC
Permalink
Great work as always!

Any chance we'll get some addendums for strong mode? Been running my
projects through it and was curious about some of the conventions.

Added https://github.com/dart-lang/www.dartlang.org/issues/1505 for the
note about collections.

But I'm also wondering about casting. As an example if you had a Map with
no type information but you know a key has a List<int>. Do you want to do

List<int> foo = myMap['foo'];

or

var foo = myMap['foo'] as List<int>;

Another example around that would be if the key is optional.

List<int> foo = myMap['foo'] ?? [];

or

var foo = myMap['foo'] as List<int> ?? <int>[];

or

var foo = (myMap['foo'] ?? []) as List<int>;
--
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.
'Bob Nystrom' via Dart Misc
2015-10-29 16:47:48 UTC
Permalink
Post by Don Olmstead
Any chance we'll get some addendums for strong mode? Been running my
projects through it and was curious about some of the conventions.
When strong mode is more polished and established, yes, definitely. Right
now, I think it's moving to quickly to really know what the best practices
are.

– 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.
Lasse Damgaard
2015-10-29 10:08:06 UTC
Permalink
Great job Bob!

I wonder why the recommendation to use final only mentions public fields?
IMO it's generally good practice to make stuff that's not modified final
including private fields, cf. the discussion on making final the default.
Post by 'Bob Nystrom' via Dart Misc
Dartisans!
Over the years, a couple of other people on the Dart team and I have
written various docs to help you write better code: the style guide,
"Idiomatic Dart", Kathy's awesome guide on doc comments, and Lasse's
excellent API naming guidelines.
Since then they sort of languished and got out of date (mine in
particular). Also, each had its own structure and organization. Some things
that were in the style guide really belonged elsewhere, etc. It was a mess.
I spent a little time tidying that up and I'm happy to give you Effective
Dart <https://www.dartlang.org/effective-dart/>.
It replaces all of those docs, modernizes them, and has a bunch of new
content. It's my best attempt at distilling what I and the people I work
with know about writing consistent, maintainable Dart code.
I hope it helps you too!
If you find errors or have suggestions, please don't hesitate to file an
issue <https://github.com/dart-lang/www.dartlang.org/issues>.
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.
'Bob Nystrom' via Dart Misc
2015-10-29 16:51:37 UTC
Permalink
Post by Lasse Damgaard
I wonder why the recommendation to use final only mentions public fields?
IMO it's generally good practice to make stuff that's not modified final
including private fields, cf. the discussion on making final the default.
There are two guidelines around final:

PREFER using a final field to make a read-only property.
Post by Lasse Damgaard
<https://www.dartlang.org/effective-dart/usage/#prefer-using-a-final-field-to-make-a-read-only-property>If
you have a field that outside code should be able to see but not assign to,
a simple solution that works in many cases is to simply mark it final.
PREFER making fields and top-level variables final.
Post by Lasse Damgaard
<https://www.dartlang.org/effective-dart/design/#prefer-making-fields-and-top-level-variables-final>State
that is not mutable—that does not change over time—is easier for
programmers to reason about. Classes and libraries that minimize the amount
of mutable state they work with tend to be easier to maintain.
Of course, it is often useful to have mutable data. But, if you don’t need
Post by Lasse Damgaard
it, your default should be to make fields and top-level variables final
when you can.
The first says that *if* you want to *implement* a public read-only
property, a final field is a good way to do it. It's to remind people that
unlike in C# and Java, there's no point in wrapping a field in a
getter/setter pair unless those do some actual computation.

The second is not about public APIs at all. (And, now that I think about
it, it should be in the usage doc, not design one...) It just says final is
better overall, regardless of whether or not it's public.

– 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.
David Notik
2015-10-30 13:54:25 UTC
Permalink
Great stuff, Bob! I'm already learning some best practices, and I'm sure
I'll be referencing this often as I evolve my Dart coding habits.

In related news, I discovered the "Reformat with Dart Style" context menu
option in WebStorm, and I've been using it more and more. It really does
improve readability.

Thank you!
Post by 'Bob Nystrom' via Dart Misc
Dartisans!
Over the years, a couple of other people on the Dart team and I have
written various docs to help you write better code: the style guide,
"Idiomatic Dart", Kathy's awesome guide on doc comments, and Lasse's
excellent API naming guidelines.
Since then they sort of languished and got out of date (mine in
particular). Also, each had its own structure and organization. Some things
that were in the style guide really belonged elsewhere, etc. It was a mess.
I spent a little time tidying that up and I'm happy to give you Effective
Dart <https://www.dartlang.org/effective-dart/>.
It replaces all of those docs, modernizes them, and has a bunch of new
content. It's my best attempt at distilling what I and the people I work
with know about writing consistent, maintainable Dart code.
I hope it helps you too!
If you find errors or have suggestions, please don't hesitate to file an
issue <https://github.com/dart-lang/www.dartlang.org/issues>.
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.
'Bob Nystrom' via Dart Misc
2015-10-30 15:59:55 UTC
Permalink
Post by David Notik
In related news, I discovered the "Reformat with Dart Style" context menu
option in WebStorm, and I've been using it more and more. It really does
improve readability.
\o/

– 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.
'Andreas Kirsch' via Dart Misc
2015-10-30 16:00:49 UTC
Permalink
Really cool, thank you!

On Fri, Oct 30, 2015 at 4:59 PM, 'Bob Nystrom' via Dart Misc <
Post by 'Bob Nystrom' via Dart Misc
Post by David Notik
In related news, I discovered the "Reformat with Dart Style" context menu
option in WebStorm, and I've been using it more and more. It really does
improve readability.
\o/
– 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
--
Why is this e-mail so short? Answer: five.sentenc.es.
--
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.
Thomas Schranz
2015-10-30 17:12:37 UTC
Permalink
This is fantastic :)
Post by 'Andreas Kirsch' via Dart Misc
Really cool, thank you!
On Fri, Oct 30, 2015 at 4:59 PM, 'Bob Nystrom' via Dart Misc <
Post by 'Bob Nystrom' via Dart Misc
Post by David Notik
In related news, I discovered the "Reformat with Dart Style" context
menu option in WebStorm, and I've been using it more and more. It really
does improve readability.
\o/
– 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
--
Why is this e-mail so short? Answer: five.sentenc.es.
--
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.
Continue reading on narkive:
Loading...