是否使用“显示”?导入Dart库时,除了意图之外还有其他好处,也许还有编译器速度吗? [英] Does using "show" when importing a Dart library have any benefits other than intention and maybe compiler speed?

查看:84
本文介绍了是否使用“显示”?导入Dart库时,除了意图之外还有其他好处,也许还有编译器速度吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我已经得到:

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.

我想另一个好处是编译器速度(dart2js),因为即使有摇晃的树,它也可以立即知道什么是依赖项而执行得更快。

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?

推荐答案

我可以想到一些:


  1. 它还减少了命名冲突;如果您因为不需要而没有从库中导入 Foo 类,则不需要完全限定其他任何 Foo 您可能正在使用的类。

  2. 减少工作区域中的混乱情况,可以避免仅通过使用而意外增加与库的耦合在那里(这只会阻止您引用其他类/函数,不会阻止您调用返回它们的东西)。

  3. 类似于(2),但智能感知列表)会更短,这可能会帮助您专注于自己关心的位。

  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.

当然,每个值

编辑:重新阅读您的文章,您已经提到2;但是由于摇摇欲坠,编译速度较不准确。仅仅因为您没有显示一个类,并不意味着您不使用它-它可以由您使用的代码在内部使用,或从函数返回给你。

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.

这篇关于是否使用“显示”?导入Dart库时,除了意图之外还有其他好处,也许还有编译器速度吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆