有人在愤怒中使用 Scala(以及对 Java 程序员的建议)吗?
自从开始使用 Smalltalk 以来,我已经成为一名 Java 程序员 10 多年了。 我认为下一个主流语言很可能是在无处不在的 Java 虚拟机上运行的语言。 我想利用 Scala(以及其他语言)具有的一些功能 - 用于类层次结构、闭包、类型推断的 case
语句,因为它将允许我编写更简洁和清晰的代码(我希望)代码。 离Smalltalk更近一点!
所有这些都是 Java 的第二天性:
- 使用
ant
进行构建 - 将应用程序/库部署到逻辑
jar
中 - 出色的 IDE 工具支持
- 编写 GUI(或使用 Swing GUI 与通过某种远程处理?)
- 第 3 方库/框架
- 配置(属性,
XML
,Spring
等) - 数据库驱动程序等
我担心玩弄之间的区别一些宠物项目,实际上却在工作场所愤怒地使用它,这有点太多了。
- 有人实现了这一飞跃吗?
- 它值得吗?
- 你学到了什么教训?
(显然人们使用 Scala - 但是有人为了更好的词而构建实际的企业应用程序吗?)
I've been a Java programmer for over 10 years since starting off with Smalltalk. It's my opinion that next big languages are likely to be ones which run on the ubiquitous Java Virtual Machine. I'd like to take advantages of some of the features that Scala (among other languages) has - case
statements for class hierarchies, closures, type inference as it will allow me to write more concise and clear (I hope) code. A bit closer to Smalltalk!
All the things that are second-nature in Java:
- Building with
ant
- deploying applications/libraries into logical
jar
s - Great IDE tool support
- Writing GUIs (or having a Swing GUI talk to it via some kind of remoting?)
- 3rd party libraries/frameworks
- Configuration (properties,
XML
,Spring
etc) - DB drivers etc
I'm concerned that the difference between playing around with some pet project and actually making the leap to using it in anger in the workplace is a bit too much.
- Has anyone made this leap?
- Was it worth it?
- What lessons did you learn?
(Obviously people are using Scala - but is anyone building actual, for the want of a better word, Enterprise applications?)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
我在现有的 Java 基础设施上使用 Scala 来查询和操作大型 xml 文档。 使用标准 Java xml 库是不可能的,或者不太容易。
我很想用它来计算投资组合绩效,但已经完成了 Java 版本。 Scala 版本更容易维护,因为更容易将公式直接转换为代码。
您可以潜入 Scala 的另一个领域是多线程。 对此没有真正的经验,但在 Scala 中似乎更容易。
要点是,暂时不要试图将其视为 Java 的替代品,而是在可以利用它的现有 Java 代码优势的地方使用它。
我使用 Intellij 和 Scala 插件作为 IDE,但它还没有。 它可以与 Maven 插件和控制台结合使用。
我也是一名 Smalltalk 程序员,喜欢在 Scala 中使用代码块。 与Java相比,代码较少,但仍然不如Smalltalk代码可读。
顺便说一句,得益于 Seaside 框架,smalltalk 社区再次增长,所以您可能想返回
我学到的或更好理解的东西:
所以是的,我认为这是值得的。
I have used Scala on our existing Java infrastructure to query and manipulate large xml documents. Was not possible using the standard Java xml libraries or not as easily.
I was tempted to use it for portfolio performance calculations, but had already finished the Java version. A Scala version would have been easier to maintain as it is easier to translate the formulas directly into code.
Another area where you can sneak in Scala is with multithreading. Have no real experience with this, but it seems to be easier in Scala.
Point is, don't try to see it as a Java replacement for now, but use it where you can utilize it strenghts next to your existing Java code.
I used Intellij with the Scala plugin as an IDE, but it is not there yet. It is do-able in combination with the maven plugin and the console.
I'm also a Smalltalk programmer and love being able to use code blocks in Scala. Compared to Java there is less code, but still not as readible as Smalltalk code.
BTW, the smalltalk community is growing again thanks to the Seaside framework, so you might want to return
The things I learned or got a better understanding of:
So yes, I think it is worth it.
乔纳斯·博内尔 (Jonas Bonér) 就是其中之一:http://jonasboner.com /2009/01/30/slides-pragmatic-real-world-scala.html
Jonas Bonér for one: http://jonasboner.com/2009/01/30/slides-pragmatic-real-world-scala.html
在我们的上一个项目中,我基本上用 Scala 代码击中了每个人的头,因为我厌倦了调试由于缺乏对 Hibernate + JBoss 的了解而导致的相同问题。 并且仍然迷失在 Hibernate 细节中。)
(这真的很神奇。编写原始系统的开发人员仍然在那里, 一个古怪的系统,主要由一堆无状态 EJB bean 和一些 Hibernate 代码与一些 SQL 混合在一起构建而成。 (基本上,我们是一个 ASP。生产集群相当小 -> 只有大约 100 台机器。)
我做了什么 -> 将各种基于 REST 的服务放在一起,其中我们重新定义了一些服务器之间的 RPC。 这使得一切都变得非常容易编码,此外,在不关注依赖关系的系统中实现公共 API。
到目前为止,我们已经开始在 JBoss 实例内外部署代码,没有出现任何实际问题。 第一次尝试在 Java 中使用 Scala
对象
时,您可能会皱起鼻子。 但除此之外,没有人真正注意到。到目前为止,距离我们真正开始,已经过去了大约5个月的时间。 我们已经进行了几次重大修改,随后落后了,但该系统比过去经过了更好的测试。 因此,虽然我们在真正学习系统时潜入了一些不好的想法,但我们现在已经能够将它们全部删除,并且非常接近生产部署。 总而言之,我认为一般人需要 2-3 个月才能停止像 Java 程序员一样编码,并“熟悉”大多数标准库。
编写 JDBC 代码而不是 ORM 系统基本上已经解决了我们几乎所有的性能问题。 速度实际上明显提高了,但这主要是因为我能够用更少的实际应用程序代码完成我想做的一切。
我正在使用的工具:
我们在重用任何旧的 java 库方面绝对没有任何问题,但我们确实倾向于将它们包装在 scala-fied 层中。 主要是为了少写代码。
拉皮条我的图书馆 模式是迄今为止最重要的模式熟悉。 “蛋糕”模式很好,但是您必须控制实例化,这有时不太有用。 我也在混合环境中使用过 Guice,也不是很难。 但我发现混合代码远没有我最初想象的那么有用,尽管这可能是因为我替换了很多非常非常糟糕的 Java 代码。
我的编辑环境主要是 OS X 上的 TextMate,但我们部署在 Linux 服务器上。
PS 是的,我知道这已经是 4 个月前的事了,但无论如何。 这是相关的,尤其是现在我们已经有了一些经验。
I basically hit everyone on the head with Scala code in our last project, as I got sick of debugging the same problems caused by a lack of understanding of Hibernate + JBoss. (It's amazing, really. The developers who wrote the original system are still there and still get lost in Hibernate details.)
What we had -> a wacky system built mostly with a bunch of stateless EJB beans wired together with some hibernate code tossed together with some SQL. (We're an ASP, basically. The production cluster is fairly small -> only around 100 machines.)
What I did -> put together various REST-based services, where we redefined the RPC between some of the servers. This is making everything very easy to code, plus, implementing a public API into what was a system where no attention was paid to dependencies.
So far, we've started to deploy code in and out of JBoss instances with no real problems. The first time you try to use a Scala
object
in Java, you'll probably wrinkle your nose. But otherwise, nobody really noticed.So far, it's been about 5 months since we really started. We've done a couple of major revisions, and subsequently are behind, but the system is far, far better tested than in the past. So, while we've had some bad ideas sneak in there while we were really learning the system, we've now been able to remove them all, and, get very close to production deployment. All in all, I'd say the typical dude needs 2-3 months to stop coding like a Java programmer, and get "familiar" with most of the standard libraries.
Writing JDBC code instead of an ORM system basically has thrown out almost all of our performance problems. The speed has been actually significantly better, but that was mostly because I was able to do everything I wanted with less real application code.
Tools I'm using:
We've had absolutely no problems with reusing any of the old java libraries, but we do tend to wrap them in scala-fied layers. Mostly just to write less code.
And the pimp my library pattern is by far the most important one to be familiar with. The "cake" pattern is nice, but you have to control instantiation, which sometimes isn't quite useful. I have also used Guice in a mixed environment, not really hard, either. But I find that mixing code is way less useful than I originally thought, though that's probably because I'm replacing a lot of really, really bad Java code.
My editing environment is mostly TextMate on OS X, but we deploy on Linux servers.
P.S. Yes, I know this is about 4 months old, but whatever. It's relevant, especially now that we have some experience.
我已将 clojure 添加到 开普勒 任务科学运营中心使用的软件基础设施中。 现在它用于进行交互式调试; 运行 REPL,加载一些类并以临时方式执行方法。
编辑:好的,所以“加载一些类并执行方法”是模糊的。 例如,我们可以加载 CRUD 类,然后执行方法将一种航天器时间转换为另一种。
可以调用其他方法将此时间转换为其他类型的时间格式,这可能对调试有用。 我们可以制作命令行工具来封装所有这些功能,但没有必要,因为一切都可以从 clojure 获得。
I've added clojure to the software infrastructure used in the Kepler mission's science operations center. Right now it's there for doing interactive debugging; run the REPL, load some classes and execute methods in an ad hoc manner.
EDIT: OK, so "load some classes and execute methods" is vague. For example, we can load our crud classes and then execute method to convert one kind of spacecraft time into another.
There are other methods that can be called to convert this time into other kinds of time formats which might be useful for debugging. We could make command line tools to encapsulate all this functionality, but there is no need to since everything is available from clojure.
另请参阅:Scala 应用程序的真实示例?
See also: Real-world examples of Scala applications?
我在相关链接上看到了这一点,并认为我应该插话,现在我们已经走了几年了。
IDE 支持有了很大的改进,IntelliJ 11 目前对 Scala 有很好的支持。 语法突出显示效果很好,但调试仍然有点烦人。
SBT 看起来很快就会取代 maven 或 ant/ivy,谢天谢地,SBT 比 Maven 更容易使用,并且更适合 Scala。 IntelliJ for one 还有一个 SBT 控制台,与交互式调试相结合确实可以使 Scala 中的调试速度非常快,不过老实说,随着语法高亮现在变得非常好,我发现我需要的调试量大大减少了。 Scala 的运行速度比 Java 好得多,而且代码似乎更不容易出错。
数据库交互似乎仍然有点悬而未决,但是有一些框架还不错,可以让您以某种方式快速使用数据库。
此时第三方库和框架比比皆是,当然您仍然可以使用任何普通的旧 Java 第三方库。
此时,我要问一个问题:为什么不在项目中使用 Scala 或其他下一代 JVM 语言? 虽然简单的答案是,现在许多开发人员还没有准备好处理 Scala,但老实说,他们需要集中精力并参与其中,而一家强制使用 Scala 的公司将走得更远。实现这一目标的方法(有时我们所有人都需要推动才能重新回到游戏中)。 此外,如果您正在进行任何类型的“企业”或大批量开发,并且您不了解函数式编程并且无法弄清楚,请帮我们大家一个忙,放下您的 IDE,否则上帝-禁止 vim,坚持使用脚本或寻找新的职业道路。
如今有许多知名公司都在使用 Scala,其中最公开的可能是 Twitter。 他们也向开源世界贡献了一些框架。
I saw this on related links, and figured I'd chime in, now we're a couple of years down the road.
IDE support has improved a great deal, IntelliJ 11 has pretty good Scala support at this point. Syntax highlighting works great, though debugging can still be a bit annoying.
SBT looks like it's quickly replacing maven or ant/ivy, and thank god, SBT is much easier to work with than Maven, and suits Scala much better. IntelliJ for one also has an SBT console, and combined with interactive debugging can make debugging in Scala go very quickly indeed, though in all honesty, with syntax highlighting now getting really good, the amount of debugging I find that I need is greatly reduced. Scala just flows much better than Java, and seems to lead to much less error-prone code.
Database interaction still seems a bit up in the air, but there are a few frameworks out there that aren't bad and can get you working with a database one way or another pretty quickly.
Third party libraries and frameworks abound at this point, and of course you can still use any plain old Java third party library.
At this point, I'm left asking the question: why wouldn't you use Scala or another next-gen JVM language for a project? And though the simple answer is that many devs just aren't ready to deal with Scala today, in all honesty, they need to get their head of their collective asses and get in the game, and a company mandating it's usage will go a long way to making that happen (all of us need a push sometimes to get back in the game). In addition, if you're doing any kind of "enterprise" or high-volume development, and you don't understand functional programming and can't figure it out, do us all a favor, put down your IDE, or god-forbid vim, stick to scripting or find a new career path.
There are many high profile companies leveraging Scala today, the most public of which is probably Twitter. They have also contributed some of their frameworks into the open source world too.
是的,人们正在使用 Scala(和 Clojure)构建实际的“企业”应用程序。 去做就对了。
当然,人们也在使用 Smalltalk,所以如果你喜欢 Smalltalk,为什么不使用它呢?
Yes, people are building actual "Enterprise" applications with Scala (and Clojure). Just do it.
Of course, people are also using Smalltalk, so if you like Smalltalk, why not use that?
我曾经在“审判愤怒”中使用过它,加载了几千兆字节的数据(对于我们所做的工作来说,工作量相当轻)。 我希望它比 PyPy 具有更高的性能和更少的内存开销。 它在内存使用方面严重失败。 非常糟糕的是,我感到震惊,羞于谈论它,并且再也没有看过它。
I used it in "trial anger" once, to load a few gigabytes of data (a fairly light workload for what we do). I was hoping it would have higher performance and less memory overhead than PyPy. It failed BADLY, on the memory usage. So badly I was horrified, embarrassed to have talked it up, and never looked at it again.