简体   繁体   English

我如何从Java过渡到Clojure?

[英]How can I transition from Java to Clojure?

After discovering Clojure I have spent the last few days immersed in it. 在发现Clojure之后,我花了最近几天沉浸其中。

What project types lend themselves to Java over Clojure, vice versa, and in combination? 哪些项目类型适用于Clojure上的Java,反之亦然,并且它们组合在一起?

What are examples of programs which you would have never attempted before Clojure? 您在Clojure之前从未尝试过的程序示例是什么?

Clojure lends itself well to concurrent programming . Clojure非常适合并发编程 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. 作为Western Mass Developer's Group的演示,Rich Hickey进行了蚁群模拟,其中每个蚂蚁都是自己的线程,所有变量都是不可变的。 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. 这不仅是因为Rich是一个了不起的程序员,也是因为他在编写代码时不必担心锁定问题。 You can check out his presentation on the ant colony here . 你可以在这里查看他对蚁群的介绍

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. 如果你打算尝试并发编程,那么我认为clojure比你从Java开箱即用的东西要好得多。 Take a look at this presentation to see why: 看一下这个演示文稿,看看为什么:

http://blip.tv/file/812787 http://blip.tv/file/812787

I documented my first 20 days with Clojure on my blog 我在博客上记录了Clojure的前20天

http://loufranco.com/blog/files/category-20-days-of-clojure.html 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. 我从SICP讲座开始,然后建立了一个平行素数筛子。 I also played around with macros. 我也玩过宏。

What project types lend themselves to using Java over Clojure, vice versa, or in combination? 哪些项目类型适合在Clojure上使用Java,反之亦然或组合使用?

A project where a GUI-building tool (such as Matisse in Netbeans) is needed would be a case where Java may still be required. 需要GUI构建工具(例如Netbeans中的Matisse)的项目可能仍然需要Java。 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.). 用Java完成的任何事情都可以在Clojure中完成,如果需要可以使用代理和gen-class,或者只需要根据需要访问Java(。,doto,new等)。 This allows Clojure projects to easily use Java libraries or legacy Java code. 这允许Clojure项目轻松使用Java库或遗留Java代码。

Which programs which you would have never attempted before Clojure ? 在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. 在我找到Clojure之前,我正在考虑一个需要JDBC的项目,它将在servlet容器中运行,我预计会进行大量的迭代开发,因为我不清楚哪些方法对我需要分析的数据起作用。 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. 我把它放在后面,因为我没有时间或耐心来进行Java所需的编译 - 调试 - 部署 - 验证循环。 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. 我现在已经在Clojure中编写了应用程序,我很高兴能够轻松地进行动态更改并能够立即检查结果。 Not to mention the joy of lock-free programming and being liberated from having to develop (and refactor) class hierarchies. 更不用说无锁编程的乐趣以及从必须开发(和重构)类层次结构中解放出来。

- "MikeM" via the clojure@googlegroups.com mailinglist - “MikeM”通过clojure@googlegroups.com邮件列表

What project types lend themselves to Java over Clojure, vice versa, and in combination? 哪些项目类型适用于Clojure上的Java,反之亦然,并且它们组合在一起?

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 ). 如果你想开发一个由Java和Clojure使用的框架,我发现在Java中编写主要的抽象(接口广告基类)比在Clojure中写它们更好(我发现Clojure的gen-class是有点乏味,而是使用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. 如果您是Hibernate的用户或任何其他框架,如果不提供程序化替代方案而大量使用Java注释,那么您将遇到一些麻烦,因为使用Clojure的数据结构模拟带注释的POJO并非易事。

Apart from that, I've experienced no use cases for which Clojure is less appropriate than Java; 除此之外,我没有经历过Clojure不如Java的用例; you have to cope with the loss of static typing, of course, which feels somewhat disconcerting at first, but tends to go away. 当然,你必须应对静态打字的损失,起初感觉有点令人不安,但往往会消失。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM