TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Ask HN: is Clojure a good all-purpose programming language?

2 点作者 shadowcats超过 11 年前
Motive for question: I really need to get out of my current language rut (PHP+Javascript) and am looking for a powerful all-purpose language to study and learn deeply over the coming years. I would rather just focus on learning one thing very well than try to pick up a half dozen new languages.<p>Current best candidate: Clojure+Clojurescript. From what I can tell, the differences are so small that they can almost be considered the same language (is this correct?). Which gives me the same benefit that JS has: no mental context-switch between client-side and server-side code.<p>Using Clojure(script) I can do a lot of stuff:<p>* Command line applications, think everything from simple cron jobs to daemons to command-line utilities (replaces: clunky PHP scripts)<p>* Backend servers (replaces: PHP, NodeJs)<p>* Web client stuff using Clojurescript (replaces: browser-side Javascript)<p>Potential bonus uses:<p>* Mobile apps, using either Clojure proper or Clojurescript+Phonegap (replaces: clunky Phonegap apps). I don&#x27;t know how feasible this is in real life, though.<p>* Desktop applications (replaces: nothing that I&#x27;ve ever tried). Again, don&#x27;t know how feasible this really is.<p>Language features that I like:<p>* Functional programming<p>* Good concurrency support<p>* Homo-iconicity, macros<p>* Lexical scoping, closures<p>* Good REPL<p>* Elegant (AFAICT), not a pile of weird hacks, quirks and gotchas like JS and PHP<p>* Compiles to JVM (Clojure) or JS (Clojurescript) which makes it&#x2F;them very portable and able to interact with a huge array of existing code&#x2F;libraries<p>So, Clojure&#x2F;Clojurescript would be my current best bet for a really powerful all-purpose language. It would also be a welcome challenge: I&#x27;ve been doing a lot of functional stuff in the past years, but Clojure would really up the ante there.<p>Feel free to chime in if you have a suggestion of a different language that could also fit the bill :)

2 条评论

gvickers超过 11 年前
It has been said time and time again, Clojure is suitable for anything that Java is suitable for. Clojurescript is extremely similar, so much so that you can expect most lib&#x27;s to be trivially refactored between CLJS&#x2F;ClJ.<p>There are some issues you are going to face, there&#x27;s no way around them. First the tooling, it is beautiful in it&#x27;s own right but takes a while to get used to. Leiningen is the preferred build tool, it cleanly handles almost everything for you but learning it seems to the beginner like just another thing preventing them from getting productive. You will miss your debugger for a while, until you realize having a debugger allowed you to write confusing, messy code that could be funged into working. There are many editors available, but when switching to clojure I decided to also learn Emacs 24 and now use it as my primary editor for every language&#x2F;document.<p>Second is productivity, coming from php&#x2F;js you will simply not have the background to lay down code quickly, let alone for-see potential issues. It took me approx. 5 months of study, every single day, to reach a comfortable point in the language where I could pump out Clojure code at a faster rate than C# code. I&#x27;m not even sure if it is faster or just my Clojure code doesn&#x27;t have as many issues or is architecturally more sound. Why I feel more productive is a mixmash of things that I could probably write a book about. It&#x27;s also very strange doing java interop with Clojure constructs. I often find myself getting caught up on clojure&#x27;s lazyness or lack of types. Once you get a handle on it though it is extremely simple and my preferred way to write java code.<p>Lastly, I seem to have poisoned my brain a bit with these ideas, I approach almost every problem now as a functional one, yielding crappy looking C# code. I often have to take a step back, stop trying to make things fit into a functional category that are clearly OO.<p>I am risking sounding like an evangelical but Clojure has changed every aspect of programming for me, and made it fun again. I find getting in &quot;the zone&quot; is much easier when things seem to spookily just work. Looking at problems through the Clojure lens more often than not resolves in a simple, composable solution.
loumf超过 11 年前
The differences between Clojure and ClojureScript are mostly because of the underlying runtime (JS vs. JVM). There are projects like cljx that let you hide that difference.<p>If &quot;mobile&quot; means &quot;Android&quot;, then I think you are right. For iOS, I don&#x27;t think there&#x27;s a mature enough way to make a native app with clojure (but PhoneGap with ClojureScript should work).<p>Finally, if &quot;all-purpose&quot; means things you can deploy on the JVM or on JS, then yes. If you wanted to make something like a device driver, I&#x27;d say no.
评论 #6991091 未加载
评论 #6991114 未加载