Fork me on GitHub
#beginners
<
2024-07-11
>
abishek00:07:10

Has anyone used clojure over eks with devspace (https://www.devspace.sh)? I got it working but am having trouble with the nrepl. It keeps losing connection. Any suggestions on how I make it work? Thanks 🙏

growthesque12:07:17

what is the most common stack for building web apps in clojure at the moment? is it kit/pedestal or do most clojurians prefer to roll everything from scratch?

Ben Sless13:07:53

That would depend on who you sample and your needs. Do you need any form of UI? Is htmx sufficient? I don't build UIs but if you're building solo you can take a look at #C013Y4VG20J or roll your own For pure backend I just use the entire metosin stack with reitit, malli, etc

🙏 1
growthesque13:07:57

htmx will probably be sufficient for what I am planning. I will check biff or possibly roll a minimal back-end + htmx. thanks.

Giu13:07:36

Interested to know wich path take at the end, I'm looking for a simple project and being my first clojure project don't want to dive into too complex architectures

Wade Mealing13:07:55

do you do know web stuff @U07AC57JGFL ?

Giu13:07:40

But not clojure specific @U0760QE0TT2 learning the lang

growthesque13:07:06

If you main priority is learning for this project, rolling your stack is the better option for sure.

Giu13:07:00

@U05V9JANJQK sorry, but, what "rolling your stack" means? :face_with_peeking_eye:

andy.fingerhut13:07:39

Sean Corfield has a demo example web server https://github.com/seancorfield/usermanager-example that he often links to in discussions like this.

respatialized13:07:10

@U07AC57JGFL I think in this context "rolling your stack" means "picking a combination of libraries to use and fitting them together yourself to build your app."

growthesque13:07:56

yeah, instead of using something like Biff which is a framework, or kit which like a pre-selection of libs as far as I can tell, you just browse around and make your own choices of libs.

didibus15:07:29

I like to roll my own. But generally it's always based around Ring when you roll your own.

Vincent15:07:58

Electric Clojure (for lightning-fast SPA, on Ring with customizations)

seancorfield15:07:08

Re: usermanager example -- it uses Compojure and Component, and links to an example using reitit and Integrant. If folks want to create more variants using other combinations, I'd be happy to link to those too. The repo also has a Polylith variant and an XTDB 2 variant (both on branches). FWIW, at work -- with our 200 module 145K line monorepo that we build nearly two dozen apps from, we use Component heavily and Compojure in nearly all the web apps.

growthesque15:07:43

@U04V70XH6 there are so many API/routing libraries for clojure and unlike with JS, most seem to be in demand. Do you know of some good resource to quickly figure out the clojure web lib landscape for beginners?

Vincent15:07:32

Routing: Pedestal, Ring are popular selections. Ring has middleware stacking as a challenge, while pedestal has its own specific "interceptor pattern" you gotta watch unfold between layers as it carries a context and error-out. SPA: Rum, lots of shops still using React and Reagent, Electric very cutting-edge Front-end otherwise: cryogen is easy way to blog in Clojure without fancy spa front-end

growthesque15:07:19

there are way more, lots of people like reitit too, pedestal is way more than just routing.

seancorfield15:07:20

@U05V9JANJQK If we were starting a new app, I'd probably use Ring + Component + reitit (instead of Compojure), but the rest of our stack would stay the same (Jetty 11 from Ring, HoneySQL/next.jdbc for SQL stuff, clojure.data.json, hato for HTTP client).

🙏 1
seancorfield16:07:37

Some of the choices are personal preference. I like middleware more than interceptors as an approach. I like Component a lot more than Integrant.

Giu16:07:14

@U04V70XH6 usermanager example has not a sample using SQL databases right?

seancorfield16:07:45

http://clojure-doc.org has a "Build your first web app" tutorial. And a tutorial for building and deploying your first library. @U07AC57JGFL The default usermanager uses next.jdbc and SQL.

growthesque16:07:59

much appreciated

Giu16:07:14

I need to work against postres and need to figure out how to map databse data to clojure data structures on functional thinking...

Giu16:07:31

oh, ok, will take a look, I downloaded but didn't dive in the code yet

seancorfield16:07:37

(usermanager uses SQLite for "production" and H2 in-memory for testing, just as an example)

seancorfield16:07:28

For PostgreSQL and data structures, read the next.jdbc docs from end to end: https://cljdoc.org/d/com.github.seancorfield/next.jdbc/CURRENT -- lots of useful information in there.

seancorfield16:07:41

In particular, the "friendly SQL functions" let you read/write plain hash maps from/to the database, and the Tips & Tricks section has a lot of stuff about PG JSON and other types.

seancorfield16:07:03

Join the #C1Q164V29 channel and ask Qs there.

🙌 1
Giu16:07:53

Thanks, will take a look. From somebody coming for a strong OOP background is difficult to take the grasp

seancorfield16:07:18

Yeah, and I bet you used ORMs heavily -- which we don't use (or need) in Clojure at all.

seancorfield16:07:42

(I've worked with ORMs quite a bit with OO languages... and I despise them 🙂 )

Giu16:07:51

Yep, one of the different reasons is being a big steping curve. Different paradigm, different lang... but excited about new challenges

Vincent16:07:10

good luck have fun ask questions when you get stuck but also figure stuff out on your own when you can

seancorfield16:07:44

I did OO for decades (C++, then Java, Groovy and some other stuff) before coming to Clojure so I sympathize 🙂

growthesque16:07:00

@U04V70XH6 how useful is java knowledge when working with clojure?

seancorfield16:07:51

There are some Java ecosystem things you need to learn (i.e., JVM stuff) but not much actual Java-the-language. You will have to learn a bit of Java's standard library for Java interop -- and be able to read Java API docs for libraries you use. The main "Java-isms" that leak through are the classpath and the stacktraces.

Ben Sless16:07:41

And don't be put off by stack traces

Ben Sless16:07:03

They are meaningful and readable, just scary for newcomers

seancorfield16:07:04

You can get a long way with Clojure knowing only the basics about classpath and being able to read stacktraces to find recognizable code references (and interpret a few somewhat cryptic exceptions).

seancorfield16:07:37

ClassCastException is probably the most common obstacle for beginners -- and it means "I expected X but you provided Y"

seancorfield16:07:24

user=> (1 2 3)
Execution error (ClassCastException) at user/eval138 (REPL:1).
class java.lang.Long cannot be cast to class clojure.lang.IFn (java.lang.Long is in module java.base of loader 'bootstrap'; clojure.lang.IFn is in unnamed module of loader 'app')
I expected clojure.lang.IFn (a function) but you provided java.lang.Long (a number).

🙏 1
didibus17:07:46

Java knowledge is very useful down the road especially for advanced things and once you start needing to dip into its large library ecosystem. But you don't have to get there for a while. Like others said, you can do a lot without. As for what to choose for your first website. I know in other languages you want to learn "what people use". That's because every JS framework is like its own beast to master. Rails is almost its own language, some people don't even learn Ruby, they learn Rails directly. But in Clojure, what you want to do is learn the fundamental building blocks and how they connect. There's no "big thing to learn that everyone uses". Each building block is simple, and has good composition with other blocks. What you want to do is understand the blocks and how they assemble, what's the purpose of each, etc. For that, as a beginner, you should start with the version of each block that has the smallest surface. I would recommend: 1. Ring + Jetty : As the webserver 2. Compojure : For routing 3. Hiccup : For generating HTML 4. Htmx : For adding some interactivity to your site 5. Next.jdbc + H2DB : As a SQL database 6. HoneySQL : To write DB queries 7. Migratus : For DB model migrations 8. Clojure.test : To write unit tests and integ tests 9. Tools.deps/build : For dependency and build management 10. Clojure.data.json : To JSON encode/decode 11. Clojure.tools.logging + logback : For logging 12. Component : For lifecycle management of stateful resources 13. Clojure.core.spec : For validation 14. Buddy : For auth and security 15. Metrics-clojure : For capturing metrics You don't even need all this for a little website project. But I included a complete set of the fundamental blocks for a serious professional production setup. Each one of these blocks I chose an approachable and simple option that is well supported and viable. Once you used all this to make a website. You'll understand what each block does, and if for any of them you hit a limitation, or don't love using them, that's when you can explore alternatives to that block. You'll know what to look for, and how to swap it out at that point. And that's the benefit of the Clojure composable library approach, you'll be able to replace each one if there's another one that does something you need that the current one didn't, or if you just don't vibe with the feel of it and prefer the feel of another.

🙏 1
💯 1
👏 1
didibus18:07:07

I have a very stupidly simple example of using some of those here: https://github.com/didibus/simple-website-with-posts/tree/main It's not got tests, and the code isn't structured in a way that you'd want to add more and more things. But it shows you how little is needed for basic website functionality and how easy it can all be. You can mess with it, try to expand it, see how you'd want to start breaking things up into better organized namespaces, and so on.

jumar05:07:09

@U04V70XH6 would you mind elaborating on > I like middleware more than interceptors as an approach. I like Component a lot more than Integrant.

seancorfield17:07:08

For me, both middleware and Component take a simpler approach to the problems they address. They both have fairly limited scope and provide "just enough" functionality to address the problems they are designed for. Both interceptors and Integrant are more flexible and offer more "knobs and dials". That's my high-level elaboration.