r/Clojure • u/tremendous-machine • Jul 17 '22
Anyone using the Kit framework?
Hi, only found out about the Kit framework today, and am curious to hear if others are using it, and if so what they think of it. (Or if not, what kept you away!)
thanks
19
u/kwrooijen Jul 18 '22
I've never used it myself so I can't say anything about the quality of the actual framework, but looking at the home page:
Using Clojure tools, getting started is as easy as:
$ clojure -Ttools install com.github.seancorfield/clj-new '{:git/tag "v1.2.381"}' :as new
$ clojure -Tnew create :template io.github.kit-clj :name yourname/guestbook
I just think to myself: In what world is this "easy"? Sure it's easy to copy and paste, but this is far from user friendly. Compare it to e.g. Rails
gem install rails
rails new guestbook
or Phoenix
mix archive.install hex phx_new
mix phx.new guestbook
Again, the framework itself might be excellent, but I'm always surprised at the verbose tooling around these things.
49
u/therealdivs1210 Jul 18 '22
This is because of the shitty Clojure CLI.
It used to be as simple as:
$ lein new kit guestbookbut apparently the community decided that this was making clojure available to lowly plebs, and REAL clojurians should be happy to type:
$ clojure -Ttools install com.github.seancorfield/clj-new '{:git/tag "v1.2.381"}' :as new
$ clojure -Tnew create :template io.github.kit-clj :name yourname/guestbook22
u/yogthos Jul 18 '22
Yeah, I think lein got things right with having simple and easy to remember commands for common tasks. The reality is that there are a handful of things that vast majority of projects need. These should be supported out of the box and shouldn't require any ceremony. I still find myself looking up basic things using deps that were never a problem with lein. But as you say, deps is what the community is going with, so not much point fighting it at this point. Kit does add a bb.edn by default though to make things easier. So, you can run stuff like
bb repl,bb test, andbb uberjarwithout having to remember the incantations for deps.6
u/Borkdude Jul 18 '22
Cool! Note that you can also do `(clojure "-M:nrepl")` or so with bb, then the call will work cross-platform. Shelling out to `"clj"` does not work on Windows AFAIK.
1
u/yogthos Jul 18 '22
Ah TIL! Any chance of a small pr to fix up the script to make it windows compatible, I don't have windows available to test on. :)
3
u/jpmonettas Jul 18 '22
Interesting. I went from lein to clojure cli just for the reason that lein wasn't simple to me. While commands look shorter and easier to remember, is hard to go from command to the code that is doing the thing.with cli I found once I learned some basics everything is just clojure function calls, and no magic.
But I understand that isn't what people is used to on other languages.
I wander if there is a way of having both, short, clear and powerful/sound
4
u/yogthos Jul 18 '22
This could be solved by just having a few built in commands that are privileged in the tools. Things like compiling, testing, making an uberjar, etc. are common across projects. I think it would be nice to have these supported out of the box while allowing people to make their own scripts if they run into limitations.
17
u/guywithknife Jul 18 '22
As a longtime Clojure user (summer 2009), I never got behind the official tools. They added complexity yet didn’t give me personally anything to warrant it.
14
9
u/joinr Jul 19 '22
I resemble this comment. Still can't get the CLI working in a proxy environment (work constraints) where I had lein working fine years ago.
14
u/gabrielgio Jul 20 '22
Man, this! I don´t understand how short sighted they have to be to come up with something like this. I remember trying clojure before they released deps.edn. You would read the docs and you wouldn´t know how to deploy ur app, how to create a jar file, nothing. Months later I found out they were using maven directly to manage their dependencies. Why the fuck they didn´t document that? Why didn´t they throw a couple of lines in the docs explain how they would do things, how to generate a jar. Thank god for lein.
Now they have a second take on tooling and they come up with that? For fucking real? I'm so pissed at them because I love the lang but hate their tooling and their decision around it. "bUt yOu jUsT NeEd tO ReAd tHe cOdE" yeah try read the code (if you can find the right place to look at) when you learning the language. Again why would they do that? They don´t want to get new people in the language? they just don´t care? Their docs are so bad and they use "the lang is simple" bullshit excuse.
14
u/therealdivs1210 Jul 20 '22
Completely agreed.
I love Clojure the language, but these decisions have been extremely off-putting.
But open source is not about us, so...
4
u/radsmith Jul 31 '22 edited Jul 31 '22
Soon, if you want to install Clojure and set up a Kit project on a new machine, it will be as easy as this:
# Install Clojure and the neil tool (one-time setup) $ brew install clojure babashka/brew/neil # Create a new app with the io.github.kit-clj/kit template $ neil new io.github.kit-clj/kit yourname/appThe
neil newcommand is available today and works with any deps-new template so you can use it to create scratch projects, libs, etc...For Kit specifically, the
io.github.kit-clj/kittemplate has a PR open and is in-progress.2
u/therealdivs1210 Jul 31 '22
That's great, thanks!
But it still shows that the official tooling sucks.
4
u/radsmith Jul 31 '22
I'm sorry you feel that way. I hope this doesn't discourage you or anyone else from trying out
tools.depswith some additional helpers in the future.Remember, Leiningen itself was created by the community, not the core team. With
tools.deps, we have an even better foundation, with native support for things like filesystem and Git-based deps.It will take time to migrate, but there's nothing stopping the community from having a great developer experience with
tools.depsin 2022. We just haven't gotten around to coding it quite yet. :)3
u/didibus Aug 02 '22
Ya, I think a lot of the tooling the core team is doing is kind of lower level, it creates a good foundation and makes building higher level tools on top easier. That second layer is what we're missing.
For example, something that could install a tool globally would be great, like add a shim in
/usr/bin, but work in all OS, so as to make Clojure tools and CLI apps feel like native command line apps.4
u/radsmith Jul 31 '22 edited Jul 31 '22
Reposting my comment from deeper in the thread:
Soon, if you want to install Clojure and set up a Kit project on a new machine, it will be as easy as this:
# Install Clojure and the neil tool (one-time setup) $ brew install clojure babashka/brew/neil # Create a new app with the io.github.kit-clj/kit template $ neil new io.github.kit-clj/kit yourname/appThe
neil newcommand is available today and works with any deps-new template so you can use it to create scratch projects, libs, etc...For Kit specifically, the
io.github.kit-clj/kittemplate has a PR open and is in-progress.2
2
u/yel50 Jul 19 '22
I'm always surprised at the verbose tooling around these things.
I used to write it off as a side effect of java's history of needing to be useable for large, monolithic projects that have had teams of 20+ developers working on them for a decade. those projects simply got complicated. but then I used dotnet. it came from that same background but has remarkably simple tools.
as with all things java, at the end of the day I blame maven and gradle. they make the build process as convoluted as possible and that's what the community got used to.
2
u/lordmyd Jul 21 '22
Seconded. I had a Kotlin app configured with Gradle and I've lost count of how many times I'd come back to it after a couple of months to find it wouldn't build due to some problem with one of [Gradle version, Gradle Kotlin plugin version, Gradle JVM version]. Never again. Deps.edn is a walk in the park by comparison.
2
5
Jul 18 '22
[removed] — view removed comment
5
u/kwrooijen Jul 18 '22
Even though this is definitely an improvement, I just find it a bit unfortunate that we need to configure / install things to make this approachable for beginner.
(IMHO) It just seems like the standard tooling was developed for the experienced Clojurian and beginner needs were disregarded. This is just not attractive for newcomers.
6
u/Borkdude Jul 18 '22
A next version of babashka will have the ability to install a script from a remote location as a global tool.
There is a `new` script located here (which is essentially Sean's deps-new tool with one minor tweak to make it bb compatible):
https://gist.github.com/borkdude/2ee8e49803b40cf0fe284c9921388f87
When bb has the new feature, a beginner could do:
bb install --name new https://gist.github.com/borkdude/2ee8e49803b40cf0fe284c9921388f87and after that:
new --name clojure-appI hope that will make things a little bit better for beginners, but yeah, it'd be nice if the out-of-the-box tooling had a slightly less steep learning curve.
8
u/Borkdude Jul 18 '22
There is also neil which offers some features to make working with deps.edn a little easier.
5
u/radsmith Jul 31 '22 edited Jul 31 '22
For those coming back to this thread, there is now a
neil newcommand. It can create templates for Kit and it runs fast with no JVM startup time due to Babashka.time neil new io.github.kit-clj/kit yourname/app --xtdb --quartz \ --git/url https://github.com/rads/kit.git \ --git/sha cb2236503c5fd5202df28bca1551bd2128a71e23 Creating project from io.github.kit-clj/kit in app ... 0.10s user 0.04s system 95% cpu 0.147 total2
u/kwrooijen Jul 18 '22
Awesome stuff! Maybe we should make the BB toolkit the standard in the Clojure ecosystem :)
2
u/didibus Aug 02 '22
Sweet, will you provide this as a Clojure tool as well?
Like could I do:
clojure -Ttools install babashka/install '{:git/tag "v1.2.381"}' :as install clojure -Tinstall :name new 'https://gist.github.com/borkdude/2ee8e49803b40cf0fe284c9921388f87' new --name clojure-appAnd maybe also use install to install itself globally:
clojure -Tinstall :name install 'https://gist.github.com/borkdude/2ee8e49803b40cf0fe284c9921388f87' install --name new 'https://gist.github.com/borkdude/2ee8e49803b40cf0fe284c9921388f87' new --name clojure-appI do love babashka and have it installed on most of my PCs, but not always, so having this in pure Clojure would be great as well.
1
u/Borkdude Aug 02 '22
You can install neil globally in your .clojure/deps.edn like this:
https://github.com/babashka/neil#clojure
We had a "tool" implementation but this required us to maintain two different APIs and since we already have a CLI implementation, that didn't make sense to me.
1
u/Borkdude Aug 02 '22
Oh sorry, I thought your question was about neil. I completely misread because `neil new` now bundles the deps-new library.
6
u/notsohasty Jul 18 '22
I've used it to build a backend for small projects. I found it very quick to get something up and running. The predecessor framework Luminus I liked too. Would have taken me forever to choose all the libraries myself and fit them together. With Luminus or Kit it takes a few minutes.
2
u/lordmyd Jul 21 '22 edited Jul 21 '22
I had high hopes for Kit after using Luminus for a few projects a couple of years ago but overengineering killed it for me. You can no longer call HugSQL directly anywhere in your app like you could in older versions of Luminus. Instead you have to follow the call chain right from your route because your HugSQL functions have to be wrapped in a call to query-fn as configured in resources/system.edn. That means passing a query-fn parameter to every function which calls your HugSQL functions. In a large project with many sql queries that gets tedious very quickly. So instead of:
(defn myfunc [x y email]
(sql-get-pass {:em email}))... you now have:
(defn myfunc [x y email query-fn]
(qery-fn :sql-get-pass {:em email}))Someone please explain to me what the gain is here.
2
u/radsmith Aug 01 '22 edited Aug 01 '22
This is a tradeoff of implicit vs. explicit dependency injection. To write a test for the first
myfunc, you need to usewith-redefsor a similar global override mechanism.With the second
myfunc, you can pass in an alternativequery-fnfor testing. You're paying the up-front cost of writingquery-fnin return for a more targeted, self-contained approach to mocking.There are some pitfalls to
with-redefs, which in comparison makes the secondmyfuncsimpler on its own, but as you said, this style is more verbose. For me, the tradeoff is well-worth it, and apparently Kit's authors feel the same way.In general, it's good practice to keep side-effects (
query-fn) as close to the top-level of the code as possible. If you find yourself passingquery-fnthrough many layers of code (i.e. prop-drilling in React terms), there is usually a way to move the side-effect up higher in the call tree so this isn't necessary.I also suggest checking out Integrant, which is what Kit uses for explicit dependency injection. In contrast, Luminus uses Mount for implicit dependency injection. This may be helpful for understanding the tradeoffs here and deciding for yourself if it's worth having something like this for your app.
1
u/lordmyd Aug 01 '22
From a technical persepective I'm sure you're right and I confess to knowing the difference between explicit and implicit dependency injection in Clojure. I naively assumed that DI was some OOP legacy I left behind when I discovered Clojure. Maybe it's Clojure's platform leaking through. Does Racket, for example, have to deal with all this?
1
u/radsmith Aug 02 '22 edited Aug 02 '22
I naively assumed that DI was some OOP legacy I left behind when I discovered Clojure.
Clojure programs still have to deal with side-effects sometimes which is where the concept of DI is useful. The pattern of passing in
query-fnmeans there is no DI framework needed but you still get the flexibility of mocking when you write a test: just pass in aquery-fnthat reads a constant value or writes to anatominstead of a real DB. In this case it's just another name for higher-order functions. These functions are more verbose to write as an implementor, but they are very nice to use as a caller.If you're using Luminus, you've been using Mount thus far which does a good job of hiding the fact that you're using DI, but there's still extra magic happening behind the scenes to make this work. One reason some people prefer Integrant (and higher-order functions) over Mount is that it gives you more control over how the mocking happens. If you like how Mount works, there's nothing wrong with that, as it will likely be supported for a long time and there are tradeoffs here no matter what you choose.
Maybe it's Clojure's platform leaking through. Does Racket, for example, have to deal with all this?
I'm no expert on Racket but I'd guess that the approaches would be similar since it a) still has to deal with side-effects and b) as a Lisp, it has full support for higher-order functions. Just for fun I managed to find a library called Component for Racket is based on Clojure's Component, the first Clojure library created for DI.
1
u/lordmyd Aug 02 '22
Yes, I remember when Stuart Sierra introduced Component but there were many in the Clojure community that felt it was a step back into the Java world.
4
u/Siltala Jul 18 '22
Link to said framework would be a nice touch