

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

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 :)
======
gvickers
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.

------
loumf
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.

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

~~~
loumf
very commonly used.

