在 Java 项目中与 Java 搭配的最佳动态语言

发布于 2024-09-27 08:59:07 字数 237 浏览 1 评论 0原文

在大型 Java 项目中与 Java 搭配使用的最佳动态语言是什么?

我们正在考虑使用动态语言进行测试、控制器和服务。一些选项是 Groovy、JRuby 或 Jython。每种方法的优点和缺点是什么?理想情况下,我们既能够从动态语言调用 Java,也能够从 Java 调用动态语言。

编辑:如果有帮助,我们将 Hibernate 与 PicoContainer 和 Webwork 一起使用。

谢谢, 亚历克斯

What is the best dynamic language to pair with Java on a large Java project?

We are considering using a dynamic language for tests, controllers, services. Some options are Groovy, JRuby or Jython. What are the pros and cons of each for this? Ideally we'd be able to call Java from the dynamic language as well as call the dynamic language from Java.

EDIT: If it helps, we're using Hibernate with PicoContainer and Webwork.

Thanks,
Alex

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

一个人的夜不怕黑 2024-10-04 08:59:07

实际上有三种动态语言可以与 Java 提供非常无缝的互操作:scala、groovy 和 clojure。从那里,我会问你的团队他们更愿意使用哪种语言工作,或者让他们尝试每种语言的原型,看看他们的想法。

如果团队效率一开始并不重要,那么看看每种语言试图解决什么问题:

  • Groovy 对于经验丰富的 Java 开发人员来说非常宽松但很自然,并且由于它是鸭子类型,因此允许快速原型开发。
  • Scala 将使您能够编写 DSL,使其成为您想要用更类似于您描述问题的语言来解决问题的框架和工具。
  • Clojure 将强加 lisp 的函数式编程和不可变状态概念,并且可能非常自然地适合人工智能、自然语言处理等问题。

最后,我走上了寻找完美语言作为项目基础的道路发现没有完美的语言。我上面提到的所有语言都编译为本机 JVM 字节代码,并且非常可靠。有时,您只需要选择一种可能不如其他语言酷但可以帮助您解决问题的语言。

There are really three dynamic languages that offer a very seamless interop with Java - scala, groovy and clojure. From there, I'd ask your team which language they would rather work in or have them try a prototype in each language and see what they think.

If the team efficiency isn't important in the beginning, look to what problem each language attempts to solve:

  • Groovy is going to be very loose but natural to experienced Java developers and allows fast prototype development due to it's duck typing.
  • Scala is going to enable you to write DSLs making it a good for frameworks and tools where you want to solve the problem in a language more akin to how you would describe the problem.
  • Clojure is going to impose lisp's functional programming and immutable state concepts and could be a very natural fit for problems in AI, natural language processing, etc.

Finally, I've gone down the path of looking for the perfect language to base projects on and have found there is no perfect language. All of the languages I've mentioned above compile to native JVM byte code and are quite solid. Sometimes you just need to pick a language that might not be as cool as the others but gets you on the way to solving your problem.

物价感观 2024-10-04 08:59:07

我推荐 Groovy,主要是因为它与 Java 无缝互操作,并且几乎是 Java 的超集,因此非常容易Java 开发人员学习。我绝对没有证据支持这一点,但根据道听途说、猜测和个人经验,我怀疑 Groovy 社区比 JRuby 或 Jython 的社区大得多。

顺便说一句,在我看来,Groovy++ 还太不成熟,无法考虑用于生产用途。

I recommend Groovy, principally because it interoperates seamlessly with Java, and is almost a superset of Java, so very easy for a Java developer to learn. I have absolutely no evidence to support this, but based on hearsay, guesswork, and personal experience, I suspect the Groovy community is much larger than that of either JRuby or Jython.

Incidentally, Groovy++ is way too immature to consider for production use, in my opinion.

孤城病女 2024-10-04 08:59:07

当然,答案在一定程度上取决于品味和灵活性。如果有人没有使用 Ruby 或 Python 的经验,那么 Groovy 的语法将更接近 Java(事实上它是 Java 的超集),因此更容易销售。

我无法真正谈论 JRuby,因为我还没有使用过它。

在您列出的三个工具中,Groovy 可能为您提供了最简单的与 Java 的互操作。它在 EasyB 中还有一个非常好的 BDD 库,我非常喜欢。从消极的一面来看,我认为 Groovy 的功能或语法并没有真正很好地结合在一起。它有点像 Java 的一大堆单独的扩展。

Jython当然是Python所以语法不同,但也具有Python的所有一致性。互操作在脚本级别非常好,但如果您想在 Jython 中编写从 Java 调用的预编译类,那么至少在过去会有点尴尬。对我来说,Groovy 的另一个主要优点是您有一个真正的 REPL 来与 Java 项目交互。

我还要提到 Clojure,语法更加不同,但 Java 互操作非常出色,可能是最好的,并且您再次拥有 REPL。不利的一面是,如果人们难以适应 Ruby 或 Python 语法,那么 Lisp 可能就不再适合了。

The answer is, of course, going to depend somewhat on matters of taste and flexibility. If there are folk who don't have experience with Ruby or Python then Groovy is going to have a syntax much closer to Java (in fact it is a superset of Java), and consequently be a much easier sell.

I can't really speak to JRuby as I haven't used it.

Groovy gives you probably the easiest interop with Java of the three you listed. It also has a very nice BDD library in EasyB which I like a lot. On the negative side I don't think the features or syntax of Groovy really hang together very well. It can kind of feel like a whole bunch of separate extensions to Java.

Jython is of course Python so the syntax is different, but also has all the consistency of Python. Interop is very good at the script level but at least used to be a bit awkward if you wanted to write pre-compiled classes in Jython that you call from Java. The other main pro over Groovy for me is that is that you have a real REPL to interact with the Java project.

I would also mention Clojure, the syntax is even more different but the Java interop is excellent, probably the best of all, and again you have a REPL. On the down-side if folk have trouble adjusting to Ruby or Python syntax then a Lisp is probably right out.

棒棒糖 2024-10-04 08:59:07

Clojure 可能是控制器和服务的最佳动态语言。 (取决于您对“服务”的含义。Scala

和 Groovy++ 具有最好的 Java 互操作性,但它们不是动态的(在 Groovy++ 中,您可以自己决定输入什么内容。)。Scala 具有动态语言的外观和感觉。 Scala 拥有良好的测试框架 http://www.scalatest.org/ 以及规范和 AKKA 非常服务成熟,并且还有 Java API

Clojure is probably the best dynamic language for controllers and services. (depending on what you mean with "services".

Scala and Groovy++ has the best java interop, but those are not dynamic (well in Groovy++ you decide for yourself what is typed.). Scala has the look and feel of a dynamic language. Scala has good testing frameworks http://www.scalatest.org/ and Specs and AKKA is very mature for services and also has Java APIs

凯凯我们等你回来 2024-10-04 08:59:07

我建议使用 Jython。语法很干净,并且您可以获得 Python 提供的任何额外功能/便利。

例如,如果您要使用 Groovy,那么您基本上只能使用 Java 提供的功能。 Jython 还将添加 Python 的功能。

如果有帮助的话,我已经将 Jython 与 Hibernate、SOAP、Corba 和 EJB 一起使用,它比仅使用普通 Java 进行同样的操作要容易得多。

I'd suggest going with Jython. The syntax is clean, and you get whatever additional power/conveniences that Python gives you.

For example, if you were to go with Groovy, you are basically limited to only what Java will give you. Jython would add the powers of Python to that as well.

If it helps any, I've used Jython with Hibernate, SOAP, Corba, and EJBs and it is much easier than doing the same with just plain Java.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文