r/Clojure • u/ernest_as • Apr 17 '16
The State of Clojure Web Development
http://yogthos.net/posts/2016-04-17-state-of-web-clj-dev.html30
u/tolitius Apr 17 '16 edited Apr 17 '16
Creating a new web framework is fun.
Another approach is to talk to all the existing successful web frameworks / libraries creators, contributors and share the problems, see how they can be better solved together, potentially without starting a new thing from scratch, but ending up contributing to the existing ones. Yes it is a lot more selfless and it is less fun and a harder approach, but this is what community is about.
X "elite" developers doing a project and telling everyone it's good.. is not Clojure's way, but Scala's, unless Typesafe/Lightbend is where Cognitect gets the inspiration.
I am sure Luke is really good, and is able to pull it off: "to create a web framework". I still prefer libraries over frameworks, but I know the feeling: "I already know so much, I've done so many various projects, I can definitely write a web framework that will cover all the problems I'be been solving for many years". The problem is, this kind of thinking is a mind trap. The same trap that people will end up in after deciding to use Arachne for something more than a CRUD pet store. If Luke was creating a new language, a new library, a new OS, it would be a different story, but a framework.. What happened to this tweet by the way?
It is interesting how different things created by Cognitect (or its people) and pushed as "the stack" are from things officially created by Rich Hickey. I am not sure who helps whom there but compare these two lines of creations:
Rich: Clojure, ClojureScript, Datomic, core.async, transit, transducers, etc.
Cognitect: Pedestal, Om, Component, etc.
The difference is: languages and libraries vs. frameworks. And as creations go: "Simple" vs. "No So Much" by the way.
Also let's not forget that we are a very small community compare to Java, Ruby, C++, Python, or even Scala. We are a great community, but the real white elephant in the room is that nobody really knows we exist. By nobody I mean people who make budget decisions. I've been doing technical consulting for a dozen of years now, and so far 99.9999% of the time people with the money simply don't know what Clojure is.
I really doubt that the problem is that we need yet another web framework, because "Luke had it enough with small libraries". I would definitely contribute to a kickstarter if Luke said: "ok, I have this mega idea, and within a year, I am going to make Clojure (at least) as confidence inspiring as Scala for people with budgets."
Yes, "if we make a web framework that would explode the programming world as Rails did, everybody will know us...", but Rails was revolutionary in 2005, today is 2016. We need marketing, we need ideas beyond web frameworks, we need to create, talk and lead together, with, and many times without "people who work with Rich Hickey" company.
Having said that, I am not against Luke's new path, it's his personal passion, it will be fun. I am sure he'll hit $35K. LightTable did ten times that, so a "web framework" have all the chances. I just think it is important to not just be polite and supportive but also to express the true emotion. We are the people :)
5
u/levand Apr 19 '16
It's fun, and I hope it'll be useful too.
You're right - Rails was revolutionary a decade ago. If I do something on par with that, it won't have the same effect.
But viewed another way... what if having a decent web framework is table stakes for a language these days? I honestly don't think we have that yet. Luminus is great, but it doesn't fill the same slot as a Rails or a Django.
And I think Arachne can bring some interesting ideas to the table. I don't want to just clone Rails, I want to build something in Clojure, and extend Clojure's core philosophies of simplicity, applying them to the problem of making development easy, clear and fast.
We'll see how it goes.
3
u/tolitius Apr 19 '16
hey, as I said, I am sure you are quite capable and I only wish you all the best in building Arachne.
what if having a decent web framework is table stakes for a language these days?
sure, I could be wrong and not seeing it this way. and if I am, I hope Arachne can bring Clojure to the next level. Would be interesting to prove Paul wrong as well:
"If I had ever seen a job posting looking for Lisp hackers, I would have been really worried." :)
of course all these initial reactions are more emotions and guesses, since we have not seen ideas behind Arachne, so let's wait and see. if it is really good, we all win.
I would not use it because it is based on Component, and it does not seem to be pluggable from your plan, but it's just me, there are many more who are "more loyal to it", and there are also potential newcomers who might not care.. at first..
4
u/levand Apr 19 '16
Well, check it out, when it's ready. I think I've managed to pull it off such that, even though it's Component based, you'll never have to read or write any code that looks like Component, as a user. That layer is encapsulated in the Module framework - only module authors need to get involved at that level.
2
3
u/dr_win Apr 17 '16
Thanks for your thoughtful comment. I would just say that LightTable kickstarter campaign cannot be directly compared to Arachne in size, because LT's campaign was pitching to all developers. It was promising a new kind of code editor for various languages/communities. I remember it because I have backed it back then and I was doing javascript/coffeescript and didn't know about Clojure(Script).
3
u/lpedrosa Apr 18 '16
/u/tolitus pretty much captures how I feel about Arachne.
I really like clojure, mainly because it gives me a choice (and the mentality) of solid and simple libraries to build something from the ground up.
Most of the things I have been building are REST services. These need to stay simple and maintainable in the long run, so we prefer to carefully cherry-pick a bunch libraries over a framework.
Yes, "if we make a web framework that would explode the programming world as Rails did, everybody will know us...", but Rails was revolutionary in 2005, today is 2016.
Again, this is pretty much spot on. The people that are actually doing websites from the ground up, will not use clojure over Rails. IMHO, each tool has its optimal use. Pushing through with this thought sounds stubborn, and defeats the purpose of the whole clojure mentality.
I believe Clojure's simplicity really appeals to experienced developers who battled in the trenches of enterprise (web)development. In the end of the day, you just want something that will do the job and that you can:
understand when it breaks, so you can fix it
understand the code you have written in 3 months time
understand other people's code/libraries, especially when the documentation is lacking
I really wish Luke all the best with his endeavour. But I would not invest my money on yet another web framework that tries to be rails-like friendly.
3
u/dragandj Apr 17 '16
I think that many commenters are missing the point. Even if Luke creates a mega-framework-y monolith, no one forces you or anyone else to use it. The separate libraries will still exist, Luminus will still exist, we'll still be able to use whatever we feel is the best. That's the thing I love about Clojure: It is relatively easy to create your own solution, so you do not have to live by other people's choices.
7
u/adambard Apr 18 '16
Routing, templating, "views" in general, serving the app, are all IMO solved to death in Clojure. Those are the relatively easy problems, and there's never a shortage of people offering solutions to easy problems. Lifting data access to an abstraction (and ease-of-use) tier higher than SQL (with manually-written SQL migrations) would be a massive gain for Clojure web dev, usable and useful in all manner of applications.
For my part, if Luke can create a comprehensive database integration to compete with the stories from Django and Rails -- migrations, easy data access (with ORM ease-of-use, if not ORM design), etc. -- I think that would be the ideal starting point for this. The closest we've come is Korma, which helps not-at-all with migrations and for all it's fancifulness is still an SQL DSL, not a higher-level abstraction.
5
u/levand Apr 19 '16
Yep. I've put a ton of thought into data abstractions. Stay tuned.
1
Apr 20 '16
I would love to see something that allows us to place restrictions on the set of data a particular request has access to in a central place. After working with templated queries a good bit such as yesql, it's just too dangerous to try to implement restrictions on every single query, I don't trust myself.
Also maybe a common data structure similar to ring that represents sql queries, on top of which libs can do syntax.
1
5
u/jhirn Apr 18 '16
Web framework is more than routing/rendering. We need something to store data (relational please), generate validation messages and forms (internationalized), asset compilation for both js (or cljs) as well as css (or sass, garden). Maybe even throw a few "commonly used" js libraries you're going to use anyways. We also need something to manage database migrations and multiple environments (dev, test, staging).
I'd love to see a lein new _ exist that automatically created a full blown project with everything in it where I could remove/replace rather than add the rest. There's no excuse for a "rails new" option to not exist in the Clojure realm.
This framework/monolith phobia is what kills my favorite language from being practical in my day to day. I manage and work on the start through launch of 10-12 websites per year. Sometimes rails makes weird decisions (looking at you coffee script, turbo links) but I just delete those two lines in the gem file, type "rake db:setup" and praise the heavens ActiveRecord exists.
5
u/levand Apr 19 '16
Arachne will have modules to do most or all of those things, and normalizing data access is definitely a priority.
That said, if you like a template approach with a particular, opinionated set of libraries, Luminus actually does sound like something you should check out - that's almost exactly what it does. If the libraries and approaches it has chosen meet your needs, you might be really happy with it.
1
u/jhirn Apr 19 '16
Thank you. This is god's work. I will dive in at my nearest convenience but that may be a month or so ;)
3
u/yogthos Apr 18 '16
A lot of this is addressed by libraries, for example Luminus bundles bouncer by default. Asset compilation for cljs works out of the box as well. Luminus uses conman to manage a pooled database connection, migratus for migrations, and sets up dev/test environments out of the box when the project is generated.
I'd love to see a lein new _ exist that automatically created a full blown project with everything in it where I could remove/replace rather than add the rest.
That's pretty much what Luminus does actually. It sets up a project with batteries included, and you can build and deploy it right away. It comes with database config, migrations, tests, packaging, the works.
If there's a particular piece of functionality or workflow that's missing, then open an issue in GitHub and I'd love to work with you to resolve it.
5
u/adambard Apr 18 '16
Those libraries are good, but lacking when compared to the facilities that exist in frameworks in other languages. Compare bouncer to wtforms, for example; they both have similar validation capabilities, but wtforms gives you a ton of help generating HTML.
Migratus works fine, but with sqlalchemy+alembic or django or rails you can get automatically generated migrations, and full orm abstractions for your database. Sure, it's two conceptually separate concerns that are "coupled" gasp together, but maybe if I always want both of those things it's a net gain if the glue code is written and maintained by someone else.
Perhaps Luke is an architecture genius and has some way of addressing this without compromising the community's strong preference for small, single-purpose libraries. But in the more likely case, either some more comprehensive solutions need to appear, or we all just need to be OK with the fact of clojure bring a suboptimal choice for straightforward CRUD apps -- that is, 99% of web apps out there.
2
u/yogthos Apr 18 '16
I think that Clojure libraries are still maturing, but also there's a difference in the workflow in a lot of cases.
For example, I predominantly use Reagent on the front-end, and HTML generation in a validation library wouldn't be of much help there. I do however appreciate the fact that bouncer cross-compiles and I can use common validation logic on the client and the server.
I've not really found ORM to be necessary in Clojure myself. I really like the HTML templating approach extended to SQL that Yesql introduced and HugSQL builds upon. My workflow for migrations is to use
lein migratus create migration-name, write the migraitons, then runlein run migrate. Perhaps there could be a watcher that runs migrations automatically as they change, but I haven't really found it to be a huge burden so far.The nice part I found is that I can run migrations and generate queries all without having to restart the app. I often run migrations, write the queries then reload them in the repl and keep going. Most of the time I don't even have any code in the db namespace since all the query functions are generated automatically.
So, when I write a CRUD app, I generally only have to write the compojure-api endpoints on the server. Perhaps it's the types of apps I personally work on, but I don't find this workflow suboptimal to anything else I've tried.
4
u/adambard Apr 18 '16
Here's how creating Models in Django looks:
startapp coreWrite model definitions and put them in
models.pyrun
makemigrationsrun
migrateThere's an argument to be made that the equivalent Clojure just has you writing the migrations directly in SQL and working with schema-less maps in your application code and is therefore equivalent.
But the Django model definitions are used to build so much more.
Forms can be autogenerated from them, for validation and rendering
The admin dashboard is wholly built on them (you might argue you could do this with Postgres, too, but NOBODY HAS IN ALL THESE YEARS. It's just too much of a pain.).
Third-party libraries for Django make creative use of them all the time. For instance, django-rest-framework uses the models to basically do all the server-side work that you just described.
Auth can be basically built-in, because the
auth contribmodules have access to these features and can make a few tables of their own.I just don't believe this is something that can be waved away as equivalent to SQL plus some helpers. Migratus and HugSQL do their jobs well, but they're simply not on the same level in terms of ease-of-use and rapid development, which I find strange because the latter is definitely something Clojure developers tend to value.
4
u/sveri Apr 18 '16
Actually the admin backend generated by django was the one thing that I wish we had in clojure. That's why I started working on closp-crud. It is nowhere near as far as django, but, if I have enough time I will at least get close to it.
That said I think it is useful already, as it generates migrations, db access layer, routes and html templates and integrates into closp.
1
u/yogthos Apr 18 '16
Right, I prefer keeping migrations as plain SQL and as I mentioned earlier I really don't see value in using the ORM approach in Clojure. I really think that the migrations scenario is more or less equivalent.
The django-rest-framework looks similar to sweet-liberty, but I agree that this approach hasn't really caught on in Clojure world.
Personally, I've just never found this to be a big burden. It usually takes minutes to write some queries and put them behind a Swagger service using compojure-api. However, when I write my own SQL, I can do exactly what I want, using something like django-rest-framework, or sweet-liberty means that I have to work within the scope of its design.
My experience is that it can often get frustrating when you want to do something conceptually simple, but that doesn't mesh well with the the design of the framework.
That said, I certainly don't see any harm in having something like that available for people who like that sort of stuff. It just doesn't sound like Arachne aims to solve that problem either.
3
u/jhirn Apr 18 '16
Well this has come a long way since I last looked at it ( which was a while ago, for sure). I didn't see anything for css or sass. I'd also like to see things like cljs by default and without running figwheel, similar to how asset pipeline is ready to go for coffee and scss when running rails server. It's the white glove things like this that annoy me when leaving Rails. Then again it might be these types of things that annoy people coming to rails.
Also korma was a real disappointment last I used it and a sql helper is just not enticing. Not to mention all the validations, error handling and add-ons the conventions of active record can afford. This might be too much for Luminis to take on but AR was core to rails' success.
Anyways next time I take a look I'll seek you out to give you feedback. I'm very glad to see a framework for web stuff in Clojure. I know a lot of people on the fringe of embracing Clojure who aren't happy with the lack of batteries included, opinionated convention heavy frameworks. Too many special snowflakes and sometimes, easy beats simple.
5
u/ndroock1 Apr 18 '16
Imagine how this reads to a newbie or to someone who still has the freedom to choose between Rails, Django, etc. The proposal sounds as if, until Arachne arrives, web development is better done with Rails. The quote "... building a full system is complex and labor-intensive ... ( with Clojure )" may be true but contradicts the widely available praise of Clojurescript. What is it exactly that Rails does which can't be done currently with Clojurescript? Both seem quite capable to me. See also: http://public-action.org/content/polyglot-leveraging-ruby-rails-and-clojurescript
4
u/notunlikethewaves Apr 18 '16
It's a sad truth, but you're right. When pitted against Rails, Sinatra, Django, Flask, Play and even Phoenix, the Clojure web ecosystem is just not strong enough to entice devs who aren't already fixated on using Clojure.
2
u/sveri Apr 18 '16
What do you think is missing, when compared to these frameworks?
I made prototypes in Rails, Django, Play and a very basic one in phoenix. None of them satisfied me. Every single one was lacking stuff, that did not happen to me with clj / cljs.
2
u/ndroock1 Apr 18 '16
I am just starting myself and sofar, I am very impressed. I have to admit that React.js deserves a large part of the credit, but I do use ClojureScript.
2
u/ndroock1 Apr 18 '16
Considering the leveraging Rails, ClojureScript article ( see link above ) and your own experience with both environments can you please give a specific example of what you feel is missing in ClojureScript? Feel free to refer to books or articles if you want.
3
u/levand Apr 19 '16
Rails can't be compared against the ClojureScript/React world directly. Single page applications and a HTTP-oriented application are different beasts.
While Arachne will obviously include full SPA support to leverage what's already there, it's primary reason for existing is shoring up the server side of the equation which I think is a bit lacking in Clojure. Especially when Clojure is so awesome already for other aspects of the server-side.
If that's not what you need right now, great! But I think a lot of people still do.
1
u/ndroock1 Apr 19 '16
I do think that I understand your point now. There is no 'Rails like eco-system' in the Clojure world and I do think that it is worth while to develop one! - In the Greek mythology Arachne was a woman who challenged Athena, the goddess of wisdom, and was transformed into a spider. Any particular reason why you chose the name Arachne for your project?
5
u/OliverM Apr 18 '16
I think it is possible to use Luminus to quickly spin up a new site in a matter of minutes, not hours. But changing out components (I tend to prefer Enlive to Selmer, for example) is not trivial, and can easily take that couple of hours. I like Luminus a great deal, and have used it as a starting point for most of my Clojure web dev work, but I've always had to heavily adapt it, and that means learning how /u/yogthos structured Luminus (and, given I'm a long-term user, how that changed between v1 and v2), just so I can unpick it.
What really appeals to me about the Arachne proposal is that it'll help experienced web devs as well as newcomers. At the moment, implementing a change in a db table requires manual threading of that change through the entire chain of REST handlers, validation, payload parsing, conversion to SQL etc - it makes me feel like a monkey, doing onerous work that could be automated with the right setup & choice of libraries (if only I knew what those were). Or, worse, tantalising me with ideas of how I could build it myself, assuming I had that time to spare!
A framework with change management built in for CRUD apps would be an enormous win.
4
u/levand Apr 19 '16
Hey! Thanks for the post... I posted a response in your comments: http://yogthos.net/posts/2016-04-17-state-of-web-clj-dev.html#comment-2630883416
Hopefully it clarifies my motivations a bit.
1
u/yogthos Apr 19 '16
Yeah definitely. Luminus is fairly opinionated at this point, and it's probably closer to Rails in that regard. It basically says use this stack, it's all configured to work for you. However, if you want a different stack then you're on your own.
This works well for people who either don't have a strong opinion on what stack to use or would use a similar one anyways. However, it's far less useful for those who have different preferences for core components. For example, if you wanted to swap out Mount of Component, then it's going to be a lot of work.
The benefit of the template approach is that you can generate a rather straightforward skeleton project, and the user has full control over the project structure from that point on. The downside is that you can't add things after you've created your app automatically. If you want to add ClojureScript support or a database to an existing app, then you have to do it manually.
I certainly appreciate that Luminus isn't for everybody, and as I said before a new framework is very welcome. It's not some sort of a zero sum game after all. I think the approach you've described so far is interesting, and I'm looking forward to seeing it in action. :)
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
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.
16
u/citrined Apr 18 '16
The projects I consult on and the products I make dev plans for haven't called for a monolithic (or merely opinionated) "framework" in a very long time. A product might need a REST API and a React front end. I'm not going to spin up a Luminous app to do everything. I'm also not going to create two Luminus apps for the tasks. Other frameworks are the same for me. But I will peek at them to see what libraries they use and how they connect pieces of the puzzle and in that way they're most valuable to me and the kind of work I do.
I think the entire industry is moving toward libraries over frameworks. Slowly but surely. Clojure has been in that way for a long time. I am satisfied with the status quo.
I would pay in to a Kickstarter to improve Leiningen, or speed Boot development, or make Auth even easier, or fund a book on writing re-frame apps. But not for everything plus the kitchen sink all at once from the ground up or a 70 line :dependencies vector.