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

Show parent comments

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 run lein 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 core

  • Write model definitions and put them in models.py

  • run makemigrations

  • run migrate

There'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 contrib modules 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.