如何从 Java 过渡到 Clojure?

发布于 2024-07-07 02:44:31 字数 173 浏览 11 评论 0原文

在发现 Clojure 后,我在过去的几天里一直沉浸在其中。

哪些项目类型适合使用 Java 而不是 Clojure,反之亦然,以及组合使用?

有哪些程序是您在 Clojure 之前从未尝试过的?

After discovering Clojure I have spent the last few days immersed in it.

What project types lend themselves to Java over Clojure, vice versa, and in combination?

What are examples of programs which you would have never attempted before Clojure?

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

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

发布评论

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

评论(4

马蹄踏│碎落叶 2024-07-14 02:44:31

Clojure 非常适合并发编程。 它提供了处理线程的出色工具,如软件事务内存和可变引用。

作为 Western Mass Developer's Group 的演示,Rich Hickey 制作了一个蚁群模拟,其中每只蚂蚁都是它自己的线程,并且所有变量都是不可变的。 即使线程数量非常多,效果也很好。 这不仅因为 Rich 是一位了不起的程序员,还因为他在编写代码时不必担心锁定。 您可以在此处查看他关于蚁群的演示

Clojure lends itself well to concurrent programming. It provides such wonderful tools for dealing with threading as Software Transactional Memory and mutable references.

As a demo for the Western Mass Developer's Group, Rich Hickey made an ant colony simulation in which each ant was its own thread and all of the variables were immutable. Even with a very large number of threads things worked great. This is not only because Rich is an amazing programmer, it's also because he didn't have to worry about locking while writing his code. You can check out his presentation on the ant colony here.

誰ツ都不明白 2024-07-14 02:44:31

如果您打算尝试并发编程,那么我认为 clojure 比您从 Java 中获得的开箱即用的要好得多。 看一下此演示文稿即可了解原因:

http://blip.tv/file/812787

我在我的博客上记录了我使用 Clojure 的前 20 天

http:// Loufranco.com/blog/files/category-20-days-of-clojure.html

我从 SICP 讲座开始,然后构建了一个并行素数筛。 我也玩过宏。

If you are going to try concurrent programming, then I think clojure is much better than what you get from Java out of the box. Take a look at this presentation to see why:

http://blip.tv/file/812787

I documented my first 20 days with Clojure on my blog

http://loufranco.com/blog/files/category-20-days-of-clojure.html

I started with the SICP lectures and then built a parallel prime number sieve. I also played around with macros.

又爬满兰若 2024-07-14 02:44:31

哪些项目类型适合使用 Java 而不是 Clojure?
反之亦然,还是组合使用?

一个包含 GUI 构建工具的项目
(如 Netbeans 中的马蒂斯)是
需要的情况是 Java 可能
还是需要的。 任何事情都在
Java 可以在 Clojure 中完成
很容易,如果有代理和gen-class
需要,或者只是访问 Java 作为
需要(.、doto、新的等)。 这
允许Clojure项目轻松使用
Java 库或遗留 Java 代码。

哪些程序是您在使用 Clojure 之前从未尝试过的?

在我发现 Clojure 之前,我是
考虑一个需要的项目
JDBC,将在 servlet 中运行
容器,我预计会做一个
大量的迭代开发,因为
目前还不清楚什么方法会
为我需要分析的数据工作。
我把它放在次要位置因为我
没有时间或耐心
编译-调试-部署-验证
Java 需要的循环。 我现在已经
用 Clojure 编写应用程序,
我很高兴
即时做出改变并存在
能够检查结果
立即地。 更别提喜悦的心情
无锁编程和存在
从必须开发(和
重构)类层次结构。

-“MikeM” 通过[电子邮件] ;受保护]邮件列表

What project types lend themselves to using Java over Clojure, vice
versa, or in combination?

A project where a GUI-building tool
(such as Matisse in Netbeans) is
needed would be a case where Java may
still be required. Anything done in
Java can be done in Clojure quite
readily, with proxy and gen-class if
needed, or just accessing Java as
needed (., doto, new, etc.). This
allows Clojure projects to easily use
Java libraries or legacy Java code.

Which programs which you would have never attempted before Clojure ?

Before I found Clojure, I was
contemplating a project that required
JDBC, would run in a servlet
container, and I anticipated doing a
lot of iterative development because
it wasn't clear what methods would
work for the data I needed to analyze.
I put it on the back burner because I
didn't have the time or patience for
the compile-debug- deploy-validation
cycling that Java requires. I've now
written the application in Clojure,
and I'm very pleased at the ease of
making changes on the fly and being
able to examine the results
immediately. Not to mention the joy
of lock-free programming and being
liberated from having to develop (and
refactor) class hierarchies.

- "MikeM" via the [email protected] mailinglist

淡淡绿茶香 2024-07-14 02:44:31

哪些项目类型适合 Java 而不是 Clojure,反之亦然,以及组合?

如果你想开发一个供 Java 和 Clojure 使用的框架,我发现用 Java 编写主要抽象(接口和基类)比用 Clojure 编写要好(我发现 Clojure 的 gen- class 有点乏味,而是使用 proxy)。

如果您是 Hibernate 或任何其他大量使用 Java 注释而不提供编程替代方案的框架的用户,您将会遇到一些麻烦,因为使用 Clojure 的数据结构模拟注释 POJO 并不是一件容易的事。

除此之外,我还没有遇到过 Clojure 比 Java 更不合适的用例。 当然,您必须应对静态类型的丢失,一开始这感觉有点令人不安,但往往会消失。

What project types lend themselves to Java over Clojure, vice versa, and in combination?

If you want to develop a framework that is to be consumed by Java and Clojure, I've found writing the main abstractions (interfaces ad base classes) in Java to be preferable over writing them in Clojure (I find Clojure's gen-class to be somewhat tedious and rather use proxy).

If you're a user of Hibernate or any other framework that makes heavy use of Java-annotations without offering a programmatic alternative, you'll have some trouble, since it's not trivial to emulate annotated POJOs with Clojure's data structures.

Apart from that, I've experienced no use cases for which Clojure is less appropriate than Java; you have to cope with the loss of static typing, of course, which feels somewhat disconcerting at first, but tends to go away.

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