如何使用 Scala 提高工作效率? (工具、IDE)
你们使用什么工具来使用 Scala?在我的学习阶段,我使用了 Scala REPL,并使用 TextMate 破解了一些代码,并使用 scalac CLI 对其进行了编译。但随着项目规模的扩大,需要更复杂的工具。
我知道 Elipse、IntelliJ 和 Netbeans 的 Scala 插件,并且我都尝试过。恕我直言,最好的一个是 IntelliJ,但距离完美还很远。
我遇到的主要问题是缺乏自动完成功能。作为一个不太高级的 Scala 程序员,我仍然不了解整个标准 API,并且必须定期在 Scaladoc 和 IDE 之间切换。这感觉就像“扼杀生产力”。但它们都无法自动完成方法参数。 (我听说方法参数不包含在编译的 scala 代码中,但是附加源代码来自动完成怎么样?)
另一个非常烦人的问题是构建过程。我正在使用 Maven 构建我的 Scala 项目并管理它们的依赖项。但尽管如此,我必须进行全面重建来测试我的更改。也许我被 Java 世界中可用的 Eclipse 增量重建宠坏了,但这对我来说是一个大问题。
我非常喜欢 Scala,并且在编码时感觉效率更高,但缺乏复杂的工具让我感觉效率较低。两者似乎都相互抵消了。
那么,我的问题是什么?我怀疑每个 Scala 程序员都会使用良好的 vim
或 emacs
以及 scalac
来完成他们的工作。那么你使用什么工具呢?您开发了哪些工作流程来提高 Scala 语言的开发速度?
编辑
澄清我对方法参数自动完成的看法。
val myList = "foo" :: "all your base" :: Nil
myList.partition(_.length > 3)
对于上面的代码,IntelliJ 未能向我提供分区所需的信息,我必须传递 () =>;布尔函数。事实上,IntelliJ 不会检查此约束。我可以传递一个
String
并且 IntelliJ 在我进行编译之前不会指示我的错误。
What Tools do you people use to work with Scala? For my learning phase, I used the Scala REPL and hacked some code with TextMate and compiled it with the scalac
CLI. But as the projects grow in size, much more sophisticated tools are required.
I am aware of the Scala plugins for Elipse, IntelliJ and Netbeans and I tried them all. The best one is IMHO IntelliJ, but still far away from being perfect.
The major issue I have is the lack of auto completion. As a not-so-advanced Scala coder, I still dont know the whole standard API and have to switch between the Scaladoc and IDE regularly. This feels like "killing productivity". But they all fail to auto-complete method arguments. (I heard that method arguments are not included in compiled scala code, but what about attaching source to do auto completion?)
Another very annoying issue is the build process. I am using Maven to build my Scala projects and manage their dependencies. But nevertheless, I have to do a full rebuild to test my changes. Maybe I am spoiled by Eclipses incremental rebuild available in the Java world, but it feels like a big issue to me.
I like Scala very much and I feel way more productive while coding, but the lack of sophisticed tools let me feel less productive. And both seem to cancel out themselves.
So, whats my question? I doubt every single Scala programmer uses good ol' vim
or emacs
along with scalac
to do their work. So what tools do you use? What workflows have you developed to bring speed into developing with the Scala language?
Edit
Clarification what I ment with auto-completion of method arguments.
val myList = "foo" :: "all your base" :: Nil
myList.partition(_.length > 3)
For the code above, IntelliJ fail to provide me with the information that partition requires that I have to pass a () => Boolean
function. In fact, IntelliJ does not check for this contraint. I can pass a String
and IntelliJ will not indicate my error until I do a compile.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
scalac
熟悉 Scalac 的命令行选项。
-deprecation
-Xprint:all
:通过编译器阶段观察代码进度,对于查看应用了哪些隐式非常有用。-help
/-X' /
-Y` 列出所有选项。scalac 的最新夜间构建包含一个 bash 完成文件,使这些文件更易于使用。
IntelliJ IDEA
使用 Javadoc 完成方法(CTRL-Space、CTRL-Q/Apple-J)屏幕截图
问题中示例的参数信息(CTRL-P ) 屏幕截图
方法参数完成 (CTRL-< kbd>SHIFT-空格)。 屏幕截图
您需要将源代码或 javadoc 链接到 IntelliJ 中的依赖项才能查看 Javadoc。
它目前不会即时突出显示类型错误,因为复杂代码中仍然存在太多误报。不过,这即将到来。
简单构建工具
SBT 保持编译器驻留,并分析类之间的依赖关系以允许增量重新编译。它还可以监视源文件的更改并自动触发重新编译和/或测试执行。
>~compile
~test-quick
我在 http://github.com/scalaz/scalaz,您可以使用它作为参考。
scalac
Get familiar with command line options to Scalac.
-deprecation
-Xprint:all
: watch your code progress through compiler phases, very useful to see what implicits are applied.-help
/-X' /
-Y` list all options.The latest nightly builds of scalac include a bash completion file that makes these easier to use.
IntelliJ IDEA
Method completion with Javadoc (CTRL-Space, CTRL-Q/Apple-J) Screenshot
Parameter Info for the example in the question (CTRL-P) Screenshot
Method Argument Completion (CTRL-SHIFT-Space). Screenshot
You need to have the source or javadocs linked into the dependencies in IntelliJ to see the Javadoc.
It doesn't currently highlight type errors on the fly, as there are still too many false-positives in complex code. This is coming, though.
Simple Build Tool
SBT keeps the compiler resident, and analyzes dependencies between classes to allow incremental recompilation. It can also monitor for changes to source files and automatically trigger recompilation and/or test execution.
>~compile
~test-quick
I have SBT and IntelliJ project configured in http://github.com/scalaz/scalaz, you could use this as a reference.
过去六个月我每天都在使用 Scala。我仍在使用 vim(和 ctags 来查找东西)和 Maven 进行构建。在使用 JRebel 时,我取得了一些不错的成绩/liftweb.net/" rel="nofollow noreferrer">Lift Web 应用程序 - 它将动态重新加载更改,而无需重新启动服务器。
我花了一些时间研究 IDE,但很快就变得令人沮丧。一开始我确实错过了很多 Eclipse 功能,但经过一段时间的调整后,我认为我现在的工作效率并没有明显下降。
我听说 NetBeans 是当前 Scala IDE 的冠军,但我还没有亲自尝试过。
I've been using Scala daily for the last six months. I'm still using vim (and ctags to find stuff), and Maven for builds. I've gotten some good mileage out of JRebel when working on Lift web apps -- it will reload changes on the fly without server restarts.
I spent some time looking into IDEs, but it got depressing really fast. I really missed a lot of Eclipse features at first, but after a period of adjustment I don't think I'm significantly less productive now.
I've heard some rumblings that NetBeans is the current champ for Scala IDEs, but I haven't tried it first hand.
一种简单的方法是使用 fsc,一种离线编译器。它维护信息缓存,标准编译器将与 fsc(作为守护进程运行)对话并在编译期间使用其缓存信息,从而加快编译周期。
One simple way is to use fsc, an offline compiler. It maintains caches of information, and the standard compiler will talk to
fsc
(running as a daemon) and use its cached information during compilation, thus speeding up your compilation cycle.这是我对类似线程的回答。给 Ensime 大约一个小时后。我就是忍不住要说出来。我必须说它对于 Emacs 包来说写得非常非常好。
Here's my answer on a similar thread. After giving about an hour to Ensime. I just can't help but get the word out. I must say it's very, very well written for an Emacs package.
恐怕还得等Scala坚如磐石。
十年前我在使用 Java 时也遇到过同样的问题。情况更糟。
我也都尝试过。对于 Scala 2.7.7,IntelliJ 是赢家,但对于 Scala 2.8.0-SNAPSHOT,Eclipse 也不是那么糟糕。
等2.8.0发布半年再检查。它应该变得可以忍受。
I am afraid you have to wait for Scala to become rock-solid.
I had exactly the same issue with Java ten years ago. It was even worse.
I also tried them all. For Scala 2.7.7 IntelliJ is the winner, but for Scala 2.8.0-SNAPSHOT Eclipse is not that bad.
Wait half of a year after 2.8.0 is released and check again. It should become bearable.
对于 Scala 2.8,请参阅此内容,以从 Maven 获得更好的性能。
With Scala 2.8, please see this for getting better performance out of Maven.
您还应该尝试使用夜间 Scala 构建的 Netbeans 6.8。我对使用这个 IDE 进行 Scala 编程非常满意。对于构建,我有时也使用 Ant。 NB Scala 插件最好的一点是它速度快并且代码完成工作完美。
对于您给出的示例: NB 给了我这个错误
代码完成:
You should also give Netbeans 6.8 a try with the nightly Scala build. I am very satisfied programming Scala with this IDE. For building, I sometimes also use Ant. The best thing about NB Scala plugin is that it is fast and code-completion works flawlessly.
For the example you gave: NB gives me this error
code-completion:
Eclipse Scala IDE 现在已经相当成熟(从 3.0 开始)。
The Eclipse Scala IDE is quite mature now (as of 3.0).