Flutter style guide vs dart style guide

409 views
Skip to first unread message

Don Olmstead

unread,
Nov 30, 2015, 1:59:06 PM11/30/15
to Dart Misc
I've been enabling lints, http://dart-lang.github.io/linter/lints/, through .analysis_options and seeing how my codebase does. I ran the flutter specific ones and they seem to be in opposition to the standard practices that have been pushed by the Dart team. I actually got out of the habit of typing everything and moving to var but that seems to be something the flutter team does not want to do. Is there a particular benefit to this if I have a library that I would want to run in flutter?

Basically with this and strong mode I'm really not sure how my code should look.

Bob Nystrom

unread,
Nov 30, 2015, 3:52:18 PM11/30/15
to General Dart Discussion

On Mon, Nov 30, 2015 at 10:59 AM, Don Olmstead <don.j.o...@gmail.com> wrote:
I've been enabling lints, http://dart-lang.github.io/linter/lints/, through .analysis_options and seeing how my codebase does. I ran the flutter specific ones and they seem to be in opposition to the standard practices that have been pushed by the Dart team. I actually got out of the habit of typing everything and moving to var but that seems to be something the flutter team does not want to do. Is there a particular benefit to this if I have a library that I would want to run in flutter?

Basically with this and strong mode I'm really not sure how my code should look.

Our story around inference, type annotating locals, and strong mode is still kind of in flux. I see teams adopt a variety of styles and the style guide is kind of flexible right now to accommodate that.

We are seeing a lot of teams adopting strong mode, and even more people pushing for better, more reliable type inference. So, my hope is that before long we can get to a point where users can use "var" and confidently rely on rock solid inference to get a high quality static analysis story.

I think we're (finally!) making fast progress in that direction, but it will take a while for all of the pieces to settle.

Cheers!

– bob


Günter Zöchbauer

unread,
Nov 30, 2015, 3:56:20 PM11/30/15
to Dart Misc
Sounds great!

Don Olmstead

unread,
Nov 30, 2015, 4:40:15 PM11/30/15
to mi...@dartlang.org
I think the bigger surprise was that "as" was enough of an overhead that they were avoiding it. Is it that dramatic a slowdown? I ask because I tend to use it quite a bit especially when coding Polymer.dart.

On Mon, Nov 30, 2015 at 12:56 PM, Günter Zöchbauer <gzo...@gmail.com> wrote:
Sounds great!

--
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.

Kasper Peulen

unread,
Nov 30, 2015, 4:45:40 PM11/30/15
to Dart Misc
That is good news Bob! 

I've been thinking about your arguments about not using types, and with strong mode not using types makes much more sense.

Only thing I really miss though, is more support of the editor, it should quickly able to tell me what the type of a variable is.
Just by hovering some variable for example.

Maybe even some command, that could convert all untyped local variables to typed local variables, and vice versa. Commit to git without types, but if a dev prefers types, maybe for debugging or whatever, it can quickly get all the types back.

Bob Nystrom

unread,
Nov 30, 2015, 4:49:07 PM11/30/15
to General Dart Discussion

On Mon, Nov 30, 2015 at 1:40 PM, Don Olmstead <don.j.o...@gmail.com> wrote:
I think the bigger surprise was that "as" was enough of an overhead that they were avoiding it. Is it that dramatic a slowdown? I ask because I tend to use it quite a bit especially when coding Polymer.dart.

I don't know where their belief that there is a slowdown comes from. I've never personally run into any noticeable performance impact using "as" in the VM, nor have I heard anyone else mention it.

– bob

Bob Nystrom

unread,
Nov 30, 2015, 4:50:11 PM11/30/15
to General Dart Discussion, Jaime Wren, Devon Carew
On Mon, Nov 30, 2015 at 1:45 PM, Kasper Peulen <kasper...@gmail.com> wrote:
That is good news Bob! 

I've been thinking about your arguments about not using types, and with strong mode not using types makes much more sense.

Only thing I really miss though, is more support of the editor, it should quickly able to tell me what the type of a variable is.
Just by hovering some variable for example.

I totally agree. Adding Jamie and Devon to the thread for their thoughts on IDE integration for this.

Cheers!

– bob

John Messerly

unread,
Nov 30, 2015, 5:33:59 PM11/30/15
to General Dart Discussion
FWIW, I heard it from the folks working on Dart Analyzer as well.

Srdjan Mitrovic

unread,
Nov 30, 2015, 6:37:45 PM11/30/15
to General Dart Discussion
'as' is not free, as it involves a type test at runtime. In some cases the test can be eliminated by the optimizing compiler, in some cases (testing against a leaf class) the test can be quite fast. But sometimes it can be quite costly (polymorphic tests, generics involved, ...). My recommendation is to assume that 'as' has a runtime performance impact.

- Srdjan

Don Olmstead

unread,
Nov 30, 2015, 6:46:49 PM11/30/15
to Dart Misc
@Srdjan is there a way to avoid that? In Polymer its pretty common to do something like

factory FooElement() =>
 
new Element.tag('foo-element') as FooElement;

Gilad Bracha

unread,
Nov 30, 2015, 6:50:29 PM11/30/15
to Dart Misc
While "as" does entail a runtime cost, the real question is whether that cost is significant for your application. I am not aware of any evidence that would indicate that using "as" in moderation matters to overall application performance.

Don Olmstead

unread,
Nov 30, 2015, 6:59:25 PM11/30/15
to mi...@dartlang.org
The Polymer example is pretty unlikely to become hot but I have other cases where I use "as" to quiet the strong mode analysis, like when working with a Map from JSON, that could potentially be hot. I don't think there's a case where I use "as" where I'm not certain that it is the thing. There's also the using "as" after an "is" check that I use quite a bit.

Vijay Menon

unread,
Nov 30, 2015, 7:48:47 PM11/30/15
to General Dart Discussion
With respect to perf, you might benchmark if you're worried.  The "as" may have a noticeable runtime cost, but it may also let a compiler better optimize the subsequent code.

The Flutter team has asked us for a more general static cast (e.g., C++'s with no runtime cost) to quiet strong mode - we're looking into how to best do that.

Cheers,

Vijay

Bob Nystrom

unread,
Dec 1, 2015, 12:08:13 PM12/1/15
to General Dart Discussion

On Mon, Nov 30, 2015 at 4:48 PM, 'Vijay Menon' via Dart Misc <mi...@dartlang.org> wrote:
The Flutter team has asked us for a more general static cast (e.g., C++'s with no runtime cost) to quiet strong mode

assert(foo is Foo);

?

Though I guess that does require flow-sensitive analysis.

– bob

Don Olmstead

unread,
Dec 1, 2015, 1:30:54 PM12/1/15
to mi...@dartlang.org
@Vijay I wasn't suggesting not profiling it it seemed as though the flutter team did profile it since they have a rule against using "as". Having a static cast equivalent would be great to have in the language.

Vijay Menon

unread,
Dec 1, 2015, 1:51:49 PM12/1/15
to General Dart Discussion
That and, in cases like Don's example above, it's clunky to add a statement.
 

– bob

Vijay Menon

unread,
Dec 1, 2015, 1:57:32 PM12/1/15
to General Dart Discussion
Right.  According to Srdjan, my comment about the compiler taking advantage of an "as" to optimize, does not apply to the Dart  VM.

Here's a tracking issue on static cast:

Vijay Menon

unread,
Dec 1, 2015, 1:57:54 PM12/1/15
to General Dart Discussion
(Sent too soon :-))

On Tue, Dec 1, 2015 at 10:57 AM, Vijay Menon <v...@google.com> wrote:
Right.  According to Srdjan, my comment about the compiler taking advantage of an "as" to optimize, does not apply to the Dart  VM.

Here's a tracking issue on static cast:

Reply all
Reply to author
Forward
0 new messages