Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does using "show" when importing a Dart library have any benefits other than intention and maybe compiler speed?

Tags:

dart

Say I've got:

import 'dart:async' show Timer;
import 'dart:math' show Random;

I think one benefit is that you explicitly set your intentions, so later if you try to use something else you have to explicitly decide whether you'd in fact like to.

I imagine another benefit is compiler speed (dart2js), because even though there is tree shaking, it can perform faster knowing right-off what's depended on.

Does it benefit speed at runtime? Other benefits?

like image 916
David Notik Avatar asked Oct 03 '14 19:10

David Notik


1 Answers

I can think of a few:

  1. It also reduces naming conflicts; if you don't import the Foo class from the library because you don't need it, you won't need to fully qualify any other Foo class you might be using.
  2. Reduces the clutter in your "working area" which can avoid you "accidentally" increasing your coupling with the library by just "using what's there" (this only stops you from referencing other classes/functions, doesn't stop you calling things that return them).
  3. Similar to (2), but the intellisense list(s) will be shorter, which might help you focus on the bits you care about.

Of course, the values of each of these may differ from dev to dev.

Edit: Re-reading your post, you already mentioned 2; however your faster compilations due to tree-shaking isn't quite accurate. Just because you didn't show a class, doesn't mean you don't use it - it could be used internally by code you do use, or returned from a function to you.

like image 53
Danny Tuppeny Avatar answered Oct 04 '22 12:10

Danny Tuppeny