226 points · by simonpure · 6y ago · 119 comments
- instaparse: takes EBNF (and other formats) as a string and gives you a parser instantly (!!!) https://github.com/Engelberg/instaparse
- re-frame: React-Redux alternative that IMO is much easier to work with https://github.com/day8/re-frame
- reagent: React wrapper https://reagent-project.github.io/
- ring https://github.com/ring-clojure/ring
- fulcro https://github.com/fulcrologic/fulcro
More than any library, though, what keeps bringing me back to Clojure is its incredibly blissful set of persistent data structures. It's a pernicious accident of history that we are taught to accept references to mutable objects as normal, inevitable, and desirable in most CS curricula. It is much easier to develop, debug, and maintain immutable data structures instead, and I consider my good fortune every time I get to debug something in Clojure rather than in some reference-laden OOP soup.
In case anyone is interested in its ideas but is stuck with JavaScript, you may be interested in a vanilla JavaScript port I've been (very sporadically) working on: https://github.com/davezuko/re-frame. It's incomplete, and definitely lacking in many areas (documentation being the obvious one), but perhaps somebody will find it useful or want to contribute back. I've personally been using it in some internal apps for a while now.
> It's a pernicious accident of history that we are taught to accept references to mutable objects as normal, inevitable, and desirable in most CS curricula. It is much easier to develop, debug, and maintain immutable data structures instead
Except for trees and graphs and the like. immutability makes working with these much more complicated.
most of the alogrithms and datastructures that you learn in CS were developed using mutability.
I am not sure that we can even develop immutable equivalents for most of them with similar time/space complexities.
Very much a side project and I'm a bear of very little brain, so it's taking me a long long time.
Seeing Clojure and other Lisp stuff in the wild gives me hope that I can lean on enough people's documentation and source that I can eventually learn what I need.
I know some folks sneer a little at Lisp, but I really enjoy trying to learn it. I haven't felt as motivated to learn a coding language since about ten years ago when I used Perl to transfer/munge data from different LDAP systems into Zimbra.
So, thank you for sharing, this is fascinating stuff.
I wonder why.
Some developers I know and hold in high regard have almost venerated Lisp, so I've always thought there must be something to it. I just thought it wasn't something you could actually use IRL, but I was wrong. I found this out when I was recently motivated to learn Clojure, and now I am starting to grok their admiration.
The usual easy excuse is about parens, but that complaint has been put to rest so many times that it's not worth replying to anymore. (And people said the same thing about Python whitespace, but now Python is at or near the top of the pile.)
Ultimately, these complaints are superficial and serve only to justify one’s laziness.
For decades, I got excited every time a new idea around lisp or functional programming and I'd play with them for weeks. Eventually, I'd get to the big question, how do I bring this idea into development environment that solves the hundreds of other ugly real-world problems I have to deal with to make a usable application? Clojure solves that by being hosted.
Immutable data structures are great, but when it's the default, it's a huge win in cognitive-overhead. Maybe that feature isn't unique to Clojure but it's certainly not a prerequisite to being called a lips or a functional language.
Singly-linked lists are cool, but almost every other type of list is cooler, being able to read, eval and print those as well is really cool.
Yes, indeed.
TBH, I developed in Erlang for 10 years and, as a result, developed a strong preference for "immutable data structures everywhere".
Unlike LISPs that I've seen (admittedly not that many), with Erlang there simply is no global data so no vars to change - it's all done via function parameters and tail recursion (Erlang has TCO baked in, btw).
For those that aren’t as familiar with Clojure - there isn’t a rails or Django for web apps, so Coast is trying to fill that void.
Getting started with Luminus was fine, but it was often very confusing and I didn't understand a lot, whereas when I added things as I needed them and checked out a couple libraries, I had a lot easier time debugging what was wrong.
What's going to make Coast different?
There are a vast many things in which I am not an expert. The pick and choose / compose your libraries / lego approach sounds great until your trying to weigh different options (of which none seem to have a wide enough install base to be truly battle tested).
Is buddy/buddy-auth the way to go for security? Or is it Friend? The former seems to receive more recommendations as of late, whereas the latter has more activity on github. These are not the problems I want to be solving when building something.
I love the language, but the quality of Clojure's web ecosystem is... questionable.
If I were to build another webapp in Clojure, I think I'd just use something widely installed like Jersey for actually interfacing with the outside world. It'll be crufty Java, but it has nice things like StackOverflow activity, massive docs, giant userbase, etc.. etc..
Here's why I think "just use composable libraries" is a bad idea:
First it isn't very friendly to new developers. You tell them to go out there and find their libraries and they have zero clue where to start.
The second problem is its not very friendly to developers with a couple years experience either. Frameworks take care of so much stuff that most people don't know they need to take care of. Not just obvious things like connecting to an RDBMS but also very basic stuff that every website will need like CSRF protection, session management, etc.
And finally, when you rely on a wide variety of micro libraries you're actually relying a wide variety of other developers. What is going to have more support and development in the future: 10 libraries split across 10 developers with varying levels of commitment, or 1 framework with a group of developers working together on it?
You don't need to build your framework like Rails or Django. You could make it easier to plug in other libraries. But it should have a sane default for everything it needs for the benefit of both new and intermediate developers. Spring kinda works like this. It's easy to use Spring libraries for different parts but you can also just use your own.
What language can't compose libs?
The main problem is whether developers can.
To me this often is "mental dark mode". You think you're more efficient, but usually aren't.
all that to say, if there is in the Clojure ecosystem analogous, I'd like to hear about it.
om.next was before that, but it seems to be almost abandoned, also fulcro author have solved a lot of depressing pain points of om.next.
Those three work like a perfect Lego.
Experience was like.. two weeks of hair pulling, gallons of coffee and no weekends, followed by intense relief and gratitude to fulcro author Tony Kay (also pathom author Wilker Lúcio) for all that not always obvious things which make great sense in the long run. This happened to me with several great Clojure things, so I immediately knew good experience was just around the corner.
Oh and his online book http://book.fulcrologic.com/ has great general SPA insights.
Three pretty serious apps with fulcro so far.
Pedestal, on the other hand, is offering compact single data structure with linear complexity increase, plus very neat async functionality out of the box.
As for fulcro3, I have chosen it first because it was kind of successor of om.next, and in om.next I was in love with its transactional data model and all that pull syntax, - fulcro3 turned out to be even better with that.
I was and am still using reagent for simpler setups, but query language and transactions is what helps to keep sanity with larger projects.
Future consideration...
Clojurescript on Node could be a good contender, but last time I tried it, the development experience was very poor and the power of Clojure doesn’t really shine in serverless functions, so I just use Python for that which is a perfectly adequate scripting language.
It's fairly painful compared to a normal backend, and it seems like the serverless advocates are on the super high and super low end: big product teams that can justify microservices and the associated high friction, and on the other hand users/use-cases who recoil at keeping a monolithic server turned on all the time even on a wimpy cloud service.
But if you've jumped on the bandwagon, look into Datomic - Ions are the Cloure-native Lambdas there.
But in general - Do people manually deploy MySQL, Postgres, or MariaDB on EC2 servers? No, (most) people use RDS. The servers are still there, but the management is less.
Do people manually deploy RabbitMQ? No, (most) people use SQS.
Cloud providers have been working out of the same playbook for years - provide low-level compute, watch what people build, and create managed services which solve common use cases. Developers love these services, because it's less infrastructure to be on call for, and they can build products faster.
Lambda and Serverless represents the inevitable conclusion of the natural evolution of the cloud. Parts of it are still painful, but undoubtably it's getting easier and more capable.
GraalVM could totally change this.
You can reuse an awful lot of code between Clojure and ClojureScript using cljc files. In my experience it is rare to have code that you want to reuse between the browser and server that you can't make portable.
Even asynchronous code with core.async is portable! In browser, it will be single threaded while on JVM it will be multithreaded, without any extra work from you.
Specifically the 'Component' library. I really didn't enjoy working with it and it one of the most complex to understand parts of our web application.
So while this seems like a fun set of slides (I have not watched the presentation yet), it's not what I would call a great introduction to Web development in Clojure overall.
I would totally start a project with pedestal today though.
This new library, `clip`, might sit better with you:
It makes me wish José (creator of elixir) would have chosen Clojure syntax instead of Ruby.
(defn inc! [id]
(kc/exec-raw (format "UPDATE articles SET count = count + 1 WHERE id = %s" id)))
(From https://github.com/tbsschroeder/clojure-webshop-app/blob/mas...)
You don't need format it seems: https://github.com/korma/Korma/blob/master/src/korma/core.cl...