Hacker News new | comments | show | ask | jobs | submit login
Ask HN: is Clojure a good all-purpose programming language?
2 points by shadowcats 1075 days ago | hide | past | web | 5 comments | favorite
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.

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.

Using Clojure(script) I can do a lot of stuff:

* Command line applications, think everything from simple cron jobs to daemons to command-line utilities (replaces: clunky PHP scripts)

* Backend servers (replaces: PHP, NodeJs)

* Web client stuff using Clojurescript (replaces: browser-side Javascript)

Potential bonus uses:

* Mobile apps, using either Clojure proper or Clojurescript+Phonegap (replaces: clunky Phonegap apps). I don't know how feasible this is in real life, though.

* Desktop applications (replaces: nothing that I've ever tried). Again, don't know how feasible this really is.

Language features that I like:

* Functional programming

* Good concurrency support

* Homo-iconicity, macros

* Lexical scoping, closures

* Good REPL

* Elegant (AFAICT), not a pile of weird hacks, quirks and gotchas like JS and PHP

* Compiles to JVM (Clojure) or JS (Clojurescript) which makes it/them very portable and able to interact with a huge array of existing code/libraries

So, Clojure/Clojurescript would be my current best bet for a really powerful all-purpose language. It would also be a welcome challenge: I've been doing a lot of functional stuff in the past years, but Clojure would really up the ante there.

Feel free to chime in if you have a suggestion of a different language that could also fit the bill :)

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's to be trivially refactored between CLJS/ClJ.

There are some issues you are going to face, there's no way around them. First the tooling, it is beautiful in it'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/document.

Second is productivity, coming from php/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'm not even sure if it is faster or just my Clojure code doesn'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's also very strange doing java interop with Clojure constructs. I often find myself getting caught up on clojure'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.

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.

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 "the zone" 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.

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.

If "mobile" means "Android", then I think you are right. For iOS, I don't think there's a mature enough way to make a native app with clojure (but PhoneGap with ClojureScript should work).

Finally, if "all-purpose" means things you can deploy on the JVM or on JS, then yes. If you wanted to make something like a device driver, I'd say no.

Right. If I ever need to do any low-level programming, I'll have to look at something else (probably C).

Mobile and desktop are not something I focus on heavily either. It's nice to know that if that were to change, Clojure at least offers some decent options.

Thanks for the cljx tip. Is it commonly used, or more of an experimental thing?

very commonly used.

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | DMCA | Apply to YC | Contact