Fork me on GitHub
#beginners
<
2022-09-06
>
Itay Dreyfus10:09:38

Need to some advice here – started my Clojure journey as a first language a few weeks ago. I've gone through the basics and some advanced topics, but feeling a bit stuck. Basically, my main goal is to build things for the web – where should I go next? I guess my question is how to put into practice what I've learned so far. Would diving into reframe/reagent be too early? is there any middle places I should look into? I'd like to hear your thoughts!

🔥 1
Rupert (All Street)11:09:05

Client side rendered codebases (with clojurescript) require a lot more learning because the abstractions are (perhaps necessarily) leaky + you have to split logic between client and server. It's possible to build performant and interactive website that are purely server side rendered (ie. just clojure). You can also sprinkle in some HTMX or Hyperscript to make the website even more interactive (these are just HTML tags so no extra clojure library required). You could try building a server side rendered website using https://github.com/weavejester/hiccup + https://github.com/ring-clojure/ring. Start with a "Hello World" page then build it up from there.

6
tvirolai12:09:57

The book https://pragprog.com/titles/dswdcloj3/web-development-with-clojure-third-edition/ is a great resource to get into writing full-stack applications, well worth the price.

👀 1
👍 1
Itay Dreyfus12:09:59

Cool, will check it out! Have you read/used it?

tvirolai12:09:07

Yes, but admittedly mainly the earlier editions. I do own the third edition too and from what I can tell based on some cursory reading, there seems quite a bit of changes (like using Reitit instead of Compojure API etc.). I like the way the whole stack from Ring handlers to the UI are discussed in depth with examples.

Itay Dreyfus13:09:53

Cool cool! thanks 🙂

Epidiah Ravachol13:09:12

Just popping in to thank you for the thread. I'm in a similar spot and looking for that elusive next step.

✌️ 1
felipebarros16:09:51

A book that is a bit too outdated at this point but that was crucial to me and I still hold dear is Clojure Applied. It's an opinionated take on what it means to build Clojure applications after you get an understanding of the language but before you are confident to make decisions on how to go about building stuff and how to put what Clojure offers you together to solve problems. Wouldn't recommend as a primary target at this point (probably the above is a better lead) but it's a nice one to have within reach. :)

✌️ 1
kennytilton16:09:48

re-frame is one good place to start, and almost a de facto standard amongst Clojurists. The downsides are that it is somewhat ornate, the upside is that it is very well documented. It also works off a secondary store a la Redux, so one gets sucked into more or less boilerplate and code juggling just to make the framework happy. That said, most of the front end community has swallowed the secondary store pill and survived. re-frame sits atop Reagent, which is nice but glitchy and provides building blocks more than a complete solution like re-frame. Both ^^^ also involve the ReactJS/Native pill. Not recommended, but again semi-standard. If ReactNative is a target, this is a great place to start: https://github.com/PEZ/rn-rf-shadow If you want to start simple, and are OK with react, try Helix, also great. I myself have a pure Web solution here https://github.com/kennytilton/matrix which I started to document when ClojureDart turned my head. Not much doc, but it thinly wraps HTML and CSS so MDN doc works. ClojureDart (CLJD) will let you avoid React. It is brand new but quite good in its initial form. The DX might be the only weakness, but that is being worked on. Flutter/Dart are nicely stable unlike React, but nothing like the simple uniformity of HTML, and brace yourself for serious OOP. Team CLJD is making the OOP less burdensome, like any good Lisp wrapper. I am doing the same with Flutter/MX. I have a nice POC implementation, but it is undocumented until I get off social media this morning and start doing that. Belated tl;dr: as a beginner, re-frame or Helix.

👀 1
Daniel Craig16:09:20

My recommendation is to go with re-frame; it's delightful

👍 1
dorab19:09:19

Since Clojure is your first language, I'd recommend taking things slower. I'd start with applications that don't need a UI (or a very minimal text-based or even REPL-based UI). When you are ready for a web UI, consider something basic like https://github.com/seancorfield/usermanager-example That will familiarize you with the foundational libraries used in a Clojure web app. Re-frame is great, and it addresses many real-world issues you will need to consider if you are building a production web app. But that's not where I'd start.

👍 2
🙌 1
practicalli-johnny08:09:12

If you can define a specific thing you want to build, more specific advice can be shared from the community E.g. do you want to build a landing page (reagent, hiccup and some CSS), or a mobile app with react native, or a full-stack app (front end + server). So figure out specifically what you want to build and go from there The web development with Clojure 3rd edition probably covers some or all of what you want, although there are many other examples and libraries Also take a look at https://kit-clj.github.io/ to generate example projects that demonstrates how libraries can work together Reagent is a defacto standard in front end apps and very simple to work with, especially coupled with hiccup or Selma to manage content Re-frame builds on Reagent and is a lot more involved but a lot more features, especially for managing complex UI flows and events. Re-frame is too much simpler web UI's and you can use just parts of re-frame

✌️ 1
practicalli-johnny17:09:46

To start with a simple ClojureScript app, I like to use figwheel as the build tool, its simpler than shadow-cljs (although not integrated with node as shadow is) There is an article about getting started with Clojurescript and figwheel here https://practical.li/blog-staging/posts/clojurescript-workflow-with-clojure-cli-tools-and-figwheel-main/

✌️ 1
manas_marthi11:09:31

How to traverse a folder in depth first manner and print the number of files in each folder?

Martin Půda12:09:20

Try this:

(defn traverse [file]
  (when (.isDirectory file)
    (let [files (seq (.listFiles file))]
      (println (.getAbsolutePath file) ":" (count files))
      (run! traverse files))))

(traverse (File. "."))

psc13:09:15

hi! I'm trying to solve what I think is a very simple problem, but there's something I'm missing Want to have a function that takes a number (upper bound of a range), and some predicates (evaluate a number and return true or false), and returns a list (or vector or whatever) of numbers that satisfy either predicate I have this:

(defn find-range-until-number-with-conditions [m & [predicates :as all]]
  (apply (filter some-fn all) (range 1 m)))
but when I call it, like this (find-range-until-number-with-conditions 10 [multiple-of-3 multiple-of-5]) I get this error class clojure.lang.LazySeq cannot be cast to class clojure.lang.IFn I have two questions: • What I'm just getting plain wrong? • How could I debug this in order to be more autonomous at solving this kind of beginner questions? (I get that I'm passing somewhere a seq when I should be passing some function, but that doesn't help me much at this point) BTW I want this function to solve (in a more elegant way) Project Euler #1 problem, which is easily solveable like this
(reduce +
        (filter
         (some-fn #(= (mod % 3) 0) #(= (mod % 5) 0))
         (range 1 1000)))
But since I'm trying to learn, I wanted to do it the way I described above

tomd13:09:57

look at the params for apply and look at the return of filter - apply expects a fn as its first arg and filter returns a lazy seq (which is not a fn)

Martin Půda13:09:37

When you swap filter and apply , it will work (`->>` is thread-last macro):

(defn find-range-until-number-with-conditions [m & predicates]
  (->> (range 1 m)
       (filter (apply some-fn predicates))))
(find-range-until-number-with-conditions 10 odd? #(> % 5))
=> (1 3 5 6 7 8 9)

psc13:09:52

that's the small thing that I was missing, I was mistaking the order thanks3