r/Clojure • • Apr 17 '16

The State of Clojure Web Development

http://yogthos.net/posts/2016-04-17-state-of-web-clj-dev.html
74 Upvotes

51 comments sorted by

View all comments

2

u/un_passant Apr 18 '16

What I don't really get in the state of Clojure Web Development is why pedestal did not really take off. Is it just because Ring was too entrenched and good enough of am I wrong in considering that pedestal server was better ? Pedestal client side was also the only client API that made sense to me until re-frame. I like Luminus (especially with Immutant !) and am a grateful and happy buyer of the "Web Development with Clojure" book, but I put some money on Kickstarter for Arachne to help move forward pedestal-server.

4

u/yogthos Apr 18 '16

I think the main problem with pedestal is that there still isn't any simple way to get running with it. If you take what Luke says in his pitch on the context of the Pedestal stack then it's bang on.

I also don't think there's anything inherently better about Pedestal than the Ring stack. Pedestal is complected by design, while the Ring stack is modular. For example, I can run different routing libraries like Compojure or Bidi on to of Ring. Meanwhile, Pedestal decides on how the routing is done for me.

That said, I agree that it would be nice to see the Pedestal stack more forward as well.

3

u/levand Apr 19 '16

Routing in Pedestal isn't complected with anything. Routes are implemented in terms of the Interceptor abstraction in a strictly analogous fashion to the way Compojure builds routes on top of the handler function abstraction.

You can easily use Pedestal without using Pedestal routing. It would actually take about 10 minutes to set up Compojure on top of Pedestal (although at that point you'd lose most the benefits Pedestal provides over Ring).

Not that it matters that much, just wanted to clarify :)

Arachne, for what it's worth, replaces half of Pedestal's routing layer. It still uses the underlying data-based route definitions and super-fast prefix-tree route resolution, but the user-facing syntax and API for creating routes will be completely different (and much better, IMO)

1

u/yogthos Apr 19 '16

Fair enough, I was under the impression that routing was baked in. Glad to be corrected on that point. :)

I definitely like the idea of using data structures to describe routes internally, but providing a more readable API to the user. I've actually considered doing something similar with Bidi. I'd like to use a Compojure style API to declare routes, but then have the library parse it and turn it into data that can be manipulated later on.

1

u/[deleted] Apr 20 '16

Arachne, for what it's worth, replaces half of Pedestal's routing layer. It still uses the underlying data-based route definitions and super-fast prefix-tree route resolution, but the user-facing syntax and API for creating routes will be completely different (and much better, IMO)

Can you share some of these user facing syntax thoughts? I would love to share some ideas I've worked through (github.com/mikeball/tao) on this as well.

7

u/halgari Apr 18 '16 edited Apr 18 '16

There's several reasons for that I think. I will be the first to admit that Pedestal was a bit too complex when it was first released. That has changed a lot in the recent versions and I recommend that people take a look at the current state of things, as most internal things have been reduced to a few simple protocols.

Also, the feature set of Pedestal was designed for a rather specific set of goals, and those are goals that many people haven't thought much about, or simply don't need.

One such goal is "async all the way down" Pedestal (and perhaps Aleph?) is one of the few Clojure frameworks that allows you to do things like make async non-blocking calls inside a hander. So now your authentication module can make a call to a db and release the webserver thread. That's something that just can't be done in the Ring model.

Secondly, Pedestal's routing system is data driven. So it's completely possible to have routing tables that change at runtime, are post-processed by other code, etc. In that sense, the "routing code" is more like a JIT that generates a lookup table than a hard coded set of "comp-ed" functions.

These are just a few of the features that Pedestal supports that I think people are either unaware of, or don't think they need.

2

u/un_passant Apr 18 '16

Being data driven and async are indeed the benefits that I see in Pedestal. It took some efforts to wrap my head around it when it came (same for the client side, btw), but then it just made sense and seemed superior to Ring.

If arachne could be a kind of Luminus for Pedestal and give it momentum, I would consider my kickstarter funding well spent.

2

u/yogthos Apr 18 '16

That's something that just can't be done in the Ring model.

That's not actually correct. Pretty much all Clojure HTTP servers provide async extensions for Ring nowadays. Aleph, Immutant, and HTTP Kit all support async non-blocking calls inside a handler. See HTTP Kit and Immutant async docs as examples.

Secondly, Pedestal's routing system is data driven.

Bidi provides a similar approach on top of Ring, but the nice part is that you have a choice in whether you want to use it or not.

2

u/halgari Apr 19 '16

Inside the handler perhaps, but not inside the middleware. You can't pause the request parsers half way through, then continue later on, likewise you can't pause during the response logic. Sure you can return a promise, but that promise then side-steps the ring response logic, so what's the point?

And at that point, the "Ring Model" is no longer in place, you don't have "just a function" you have "just a function" that returns a promise that will return the rest of your logic.

1

u/yogthos Apr 19 '16

While that's true, it's not really an issue in practice in vast majority of situations from what I've seen. Middleware should not be the place where you have the overhead that necessitates the async functionality in my opinion.