如何应用clojure? [英] How to apply clojure?

查看:132
本文介绍了如何应用clojure?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习Clojure,我真的很喜欢它的一些功能。时间是来想到一些真正的宠物项目,我意识到我不知道如何实际使用 Clojure。



我看到许多web和模板框架(例如Compojure),但不知何故我怀疑它是否值得。我觉得从长远来看它不能满足现实世界的应用程序的需求,你可以使用Spring,Hibernate和一些Java EE堆栈来处理。



On另一方面,我在并发功能上看到了巨大的潜力,但我对如何真正使用它们的想法不太了解。



足够的背景,我的问题是: p>


  • Clojure和函数式编程的可行应用是什么?对于一个宠物项目的什么想法你可以建议哪些不会重写我做的OO / Java EE的东西到不同的语法?我正在寻找一些真正利用Clojure潜力的东西,并导致一个比OO /结构化编程更好的解决方案(不仅仅是语法)。

  • 是常见的还是最不合理,混合Clojure和Java?我的意思是在95%的Java项目中使用Clojure作为微小的库,或者在Clojure中编写的核心之上构建Java应用程序。






编辑:感谢所有伟大的答案。他们都真的鼓舞人心。

解决方案

如果你有其他要添加的东西, p>在回答问题的背景部分:



我认为你应该阅读JörgW. Mittag的回答题为Real world Haskell programming的SO问题。他做了一些优秀的点。阅读下我对现实世界中的FP的看法;



有一些以FP为中心的公司似乎对他们正在做的很好;对于一些例子,google简街(OCaml),Galois(Haskell),FlightCaster(Clojure的后端重提升;我似乎记得阅读,他们的前端目前在Rails完成)。假设自动交易策略通常使用面向FP的语言编码;这确实会有完美的意义,虽然我没有内部的数据来证实这一点。有关Clojure的其他示例,请参见为Clojure的开发做出财务贡献的公司列表。 p>

有些人似乎在解决Rails,Django等现实应用程序的需求方面取得了一定的成功。看起来他们觉得没有必要触摸J2EE&朋友。不是这些与FP有很大关系,但是它们像 FP一样,因为它们不像现在的企业语言。






至于两个实际问题:



你最近一直在想着在Clojure做什么和做它吗?显然,任何事情都可以在Java中完成(大多数事情可能已经完成),但是一种精简的语言可以使产品更清洁,更愉快的体验和更少的时间消耗等。



关于混合Clojure和Java - 我已经看到一个体面的大量的Clojure代码使用几个类直接在Java编码(无论什么原因)。我试着去绕过自己,这是一个有点痛苦,使用接口继承比类继承在Clojure中更简单,在Java代码中的意外耦合可以严重干扰Clojure代码的能力以最自然的方式做事情等。但是,完全可能在Clojure中扩展一个Java程序,它看起来像一个特别安全,对于担心的Java开发人员来说,这是一个非常简单的方法。


I am learning Clojure and I really am loving some of its features. The time is coming to think of some real "pet projects" and I realize I'm not sure how to actually use Clojure.

I see many web and templating frameworks (e.g. Compojure), but somehow I'm in doubt on whether it's worth it. I feel that in the long run it can't serve the needs of real world applications which you address with Spring, Hibernate and some pieces of the Java EE stack.

On the other hand, I see great potential in the concurrency features but I'm short on ideas on how to really use them.

Enough background, my questions are:

  • What are the feasible applications of Clojure and functional programming? What idea for a pet project can you suggest which wouldn't be rewriting the stuff I did with OO/Java EE into different syntax? I'm looking for something what really exploits Clojure's potential and leads to a solution which feels a lot better (not just in syntax) than OO/structural programming.
  • Is it common, or at least reasonable, to mix Clojure and Java? I mean either of using Clojure for tiny libraries in 95% Java projects, or building Java apps on top of the core written in Clojure.

Edit: Thanks for all the great answers. They're all really inspiring. So if you have anything else to add, go ahead and don't be put off by the fact that one has been accepted.

解决方案

In answer to the "background" part of the question:

I think you should read Jörg W. Mittag's answer to an SO question entitled "Real world Haskell programming". He makes a number of excellent points. Read on for my take on the FP in the real world issue; scroll past the horizontal line for answers to the two actual questions.

There's a number of FP-centric companies which seem to be really good at what they're doing; for some examples, google Jane Street (OCaml), Galois (Haskell), FlightCaster (Clojure for backend heavy lifting; I seem to remember reading that their frontend is currently done in Rails). Supposedly automated trading strategies are often coded in FP-oriented languages; that would indeed make perfect sense, although I have no inside data to confirm this. For additional examples to do with Clojure, see the list of companies which have made financial contributions to Clojure's development.

Some people seem to be enjoying a degree of success in addressing the needs of real world applications in Rails, Django etc. It would appear that they feel no need to touch J2EE & friends. Not that these have much to do with FP, but they are like FP in that they're nothing like the "Enterprise Languages" of the present.


As for the two actual questions:

Why not just pick up whatever it is you've last been thinking to do and do it in Clojure? Obviously anything can be done in Java (and most things probably have been), but a leaner language might make the product cleaner, the experience more pleasant and less time consuming etc.

About mixing Clojure and Java -- I've seen a decent amount of Clojure code using a couple of classes coded directly in Java (for whatever reason). I've tried going the other way around myself and it's a bit of a pain in that it's much simpler to work with interface inheritance than class inheritance in Clojure, unexpected coupling in the Java code can seriously interfere with the ability of the Clojure code to do things in the most natural way etc. Still, it's entirely possible to extend a Java programme in Clojure and it seems like a particularly safe & sane way of experimenting with it for the worried Java developer.

这篇关于如何应用clojure?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆