Hacker News new | ask | show | jobs
by lambdaba 1648 days ago
Could you say more about what/how you're using them? Like, frameworks, libs, practices (testing), editor, repls, etc.
2 comments

Sure, my go to editor for Clojure is Emacs with prelude and few major modes (CIDER, Clojure mode, paredit, smart parens, helm, etc). I use the CIDER-nrepl to jack into a REPL process within Emacs, so I can evaluate buffer's with C-c C-k. It creates a very fast feedback loop.

Clojurians don't tend to like frameworks and stuff. They're less frameworks, and more toolkits, a collection of popular libraries with config out of the box. Popular ones are Pedestal, Luminus, Edge, Compojure+ring. I started with Compojure, and I've played with luminus, Juxt's Edge, but lately I almost always bring together Reitit (a router) and Ring (jetty adapter for Clojure).

Front-end frameworks are a different story though. There are two big contenders: Reagent and Re-frame. Reagent is a Clojurescript wrapper around React that uses Hiccup (an http DSL for clojure) syntax to define components. Re-frame extends Reagent by providing a side-effects-under-the-hood framework for building single page applications. Recently, I've taken to really liking re-frame, especially with the Material-UI Reagent wrapper to ship fast.

clojure.test is the core testing library, and it's pretty robust out of the box with assertions and macros for testing conditions like Exceptions being thrown. By default it provides diffs when the test fails. There are libraries to help with testing/mocks and stuff, but I almost never use them.

It's also possible to use clojure.spec to create data generators for generative testing; however, the caveat of using clojure.spec for generators is typing your functions/type/etc too much, you'll lose the benefits of a dynamically typed programming language and probably spend more time writing the specs instead of the code. I typically use spec, or a competitor like Malli, to validate input at the system boundaries and critical code pathways.

There is so much to the Clojure ecosystem, this really only scratches the surface. I hope this helps though.

Thank you very much! Do you mind being contacted for further questions at some point? I'm generally aware of the Clojure ecosystem, have a plan to build an app and might have some further questions. Note that I ask in all eventuality that you might have the availability, I know it's pretty bold of me ;).

PS: my email is in my bio, and this is concerning the near-ish future

sure I'll reach out
I came to the comments to make a similar assertion of Clojure(script) being fun. Usually I work in IntelliJ with Cursive. VSCode with calva isn't bad.

The stack for my project is:

Backend:

Redis (no relational DB needed for my use case)

Clojure:

Carmine - (redis interop)

Reitit - Nice API definition and routing

Malli - Nice schema validation and coercion

Timbre - Logging without known RCE vulnerability ;)

Frontend:

Clojurescript

Figwheel - CLJS compiling and hot-reloading in browser. Would probably use ShadowCLJS these days though.

Rum - It's a simple wrapper around react, with Hiccup-style list syntax for HTML. Though in a do-over I'd probably try Reagent since it seems to have a bigger ecosystem of wrapped react libraries, but I really like Rum best. That said, it's also not that hard to use native JS React components with Rum.

All of the libraries and idioms in this stack guide the design to push side effects out to the edges of the program - this makes testing easier in a lot of cases. E.g., for a web request you can craft a test request, or pretty-print a literal request object and paste it into your code, then pass it to your API in Reitit without an http-server attached, and get back the result object, and assert that it matches the desired output. Clojure's mutability make it pretty simple to stub or mock calls to storage, or to create a fixture to use a test database.

Thank you! In the event you see this may I ask why not stick with Figwheel? Does ShadowCLJS do the job just as well? I remember Figwheel being impressive and it seems maintained.
Figwheel -has- been good for me, but my project is still using the even older figwheel (non-main) rewrite. There hasn't been enough pain to force an upgrade.

From reading and playing with a hello-world project, though, ShadowCLJS seems to offer roughly the same watch|build|hot-reload ability while also offering more and better NPM interop support. As it is now, I have some fairly ugly shell scripting around js packages and builds that could go away if I paid the effort to migrate to ShadowCLJS.

It would also be a lie to say that the generally positive buzz around it doesn't contribute.

If I might ask, what sort of project are you planning?