在增量编译方面,Scala中的通配符导入是否有问题? [英] Is wildcard import bad in Scala with respect to incremental compilation?

查看:129
本文介绍了在增量编译方面,Scala中的通配符导入是否有问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Scala中,从增量编译器(sbt,Eclipse中的sbt,IntelliJ)的功效和速度来看,使用通配符导入是不是很糟糕?它是否会对这些增量编译器决定在更改时重新编译的方式产生负面影响?

In Scala, is it bad, from the point of view of efficacy and speed of incremental compilers (sbt, sbt in Eclipse, IntelliJ), to use wildcard imports? Does it adversely affect the way these incremental compilers decide what to recompile in case of changes?

例如,如果是新类 X ,我只需要导入类 A B (而不是 pack > C ),写这个是否会受到处罚:

For instance, if for a new class X, I would only need to import classes A and B (and not C) from package pack, do I get a penalty for writing this:

import pack._

而不是这个?

import pack.{ A, B }

假设 A B 不依赖 C ,将 X 使用通配符导入重新编译,而不是使用更具体的导入重新编译 C 更改,或依赖关系跟踪系统是否足够智能,以实现 C 未被 X 使用,尽管通配符导入?

Assuming A and B have no dependency on C, would X be recompiled with the wildcard import and not with the more specific import when C changes, or would the dependency tracking system be smart enough to realize that C is not used by X despite the wildcard import?

推荐答案

有一点影响,但你可能不会注意到它。影响是,当引用符号Foo时,编译器必须将Foo解析为完全限定名称。它可以查找Foo的范围受到通配符导入的影响。但这一切都是在记忆中完成的,你几乎肯定不会注意到分辨率速度的微小差异,除非你在一个包中有成千上万个类的疯狂。

There is one tiny impact, but you probably won't notice it. The impact is that when there's a reference to symbol "Foo" the compiler must resolve "Foo" into a fully qualified name. The scope of where it can look for "Foo" is affected by wildcard imports. But that's all done in memory and you almost certainly won't notice such tiny differences in resolution speed unless you have something crazy like thousands of classes in one package.

除了那没有影响。如果你导入pack._和pack._中的一些任意类,你不依赖于更改,那么你的文件将不必重新编译。

Other than that, no impact. If you import pack._ and some arbitrary class in pack._ that you don't depend on changes then your file won't have to be recompiled.

这篇关于在增量编译方面,Scala中的通配符导入是否有问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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