Hacker News new | ask | show | jobs
by dfischer 4004 days ago
Is it worthwhile to explore Clojure for web-dev seriously or more as a toy?
6 comments

It's extremely serious.

The deployment is the very well understood JVM and standard web servers. There's a common HTTP middleware framework (Ring), lots of choices for HTML generation and ClojureScript allows some code-sharing with your client side (compiles to JS).

On the back-end, you could use any Java library. On the front-end, you could use any JS framework (e.g. see https://github.com/omcljs/om)

I suspect swannodette (dnolen)'s talk at EuroClojure should be a pretty compelling showcase of how Clojure is quickly blossoming in the web-dev space.
It was a cool talk, but it didn't really address adoption.

It featured (to the best of my memory):

A new data model for om next. Instead of cursors, components have a composable datomic style DSL to locate their data, which is pluggable and can be from local memory or a cached server side query.

Using this approach you can request data in new ways from the client without adding server side code.

An update on cljs in cljs (small example but showing lots of plumbing work done)

The path to react native, repls and dynamic code loading on the device (was demoed) via ambly

I think it is one of the best stacks out there for web.

Check out this:

https://github.com/bhauman/flappy-bird-demo

It uses figwheel for the dynamic changes of state when you change to code, and it renders it without reload ala Bret Victor style. The first time I saw it I was amazed. It speeds up prototyping so much.

The out of the box performance is decent as well, Ring and Hiccup is pretty lean but you can go for more heavy frameworks (I don't have any experience with those).

I personally use Reagent + Ring, found it easy to use and get productive in a day.

If you haven't used LISP or any homoiconic language before it might look little weird at first but I found it easy to explain to people.

About the toy part, what is your definition of toy?

So how do you start using this example?
You need leiningen (it's in most package managers):

https://github.com/technomancy/leiningen

Clone the repo, `lein figwheel`, http://localhost:3449/index.html

I would do something like this on my macbook:

git clone blah && cd blah && brew install leiningen && lein figwheel

I don't know what is you operating system and other details.

You need leiningen, that is the make of Clojure, the repository cloned and you are good.

Seriously. I have my misgivings with Clojure in comparison to other Lisps, but it's a serious programming language.
I'm the opposite. The idea that Clojure is just enough Lisp - that it strips down some of the syntax a bit - is one of the benefits, IMO.
I've been using Clojure in production systems for 5 years now. Average of 15req/s over 5 years - I'd say that's pretty serious.
I vote that it's worthwhile as well. We've been using Clojure full-time at ReadyForZero for over 3 years now (for web-dev as well as other tasks), and are very happy with our choice.
Have you ever used anything like rails? I come from that background and clojure doesn't seem as straight forward; for better or worse. But I like the beauty of the language.
Mmm, I've never used Ruby or Rails professionally, so I can't really speak to that. Prior to Clojure, I mostly worked with C++, Java, C#, and Python.

At its core, Clojure is basically just data and functions. Once the switch flipped in my mind, I found that to be simpler and more straight forward than any of the languages I worked with before.

When the majority of your code is side-effect-free, pure functions (and Clojure makes it very easy to structure your code this way), it becomes very easy to reason about. And very easy to test, with minimal ceremony!

P.S. When I was learning Clojure, I kinda devoured all the resources I could find. A couple interesting looks at the language from the perspective of Rubyists:

http://briancarper.net/blog/536/clojure-from-a-ruby-perspect...

http://confreaks.tv/videos/rubyconf2009-clojure-for-ruby-pro...

Is it better than plain Java? I mean, if you have the entire Java ecosystem, is it worth it to go upstream just to work in a Lisp-like language?
IMHO, absolutely. There are many wins, but the 2 biggest for us have been:

1. Clojure's tools for making abstractions are orders of magnitude better than Java's, so our codebase is significantly smaller and simpler than what it'd look like in Java.

2. Clojure lends itself very well to a REPL-oriented kind of iterative development that speeds up writing and testing code tremendously, compared to the typical Java workflow.

Writing Java with Clojure is actually kinda fun, and macros let you abstract it away when the ceremony gets thick.
Is there a Clojure/Clojurescript tutorial similar to the Hartl Rails tutorial? I have amassed quite a few Clojure books, but find the easiest way to learn is to build.
this might be a good starting point if you're looking for a simple example http://www.luminusweb.net/docs