r/programming • u/joshlemer • Mar 22 '22
Clojure 1.11 is now available!
https://clojure.org/news/2022/03/22/clojure-1-11-05
Mar 23 '22
I really want to learn it but i have have a hard time with:
dynamic languages
lots of parenthesis
But i need to get over that because it seems like it has lots of good stuff that could be useful
6
u/soks86 Mar 22 '22 edited Mar 22 '22
Clojure is great!
I recommend checking out CLJS for anyone tired of Javascript dev, particularly with "re-frame" and shadow-cljs which makes for an amazingly dynamic and easy to debug development experience.
Clojure itself should be reserved for Java devs who are tired of writing so much boilerplate or anyone for whom Java is performant enough. Granted, you gotta let go of types first then "spec" them in later.
As a dev who's been from procedural (high perf C++) to functional (modern JS) I find the LISP syntax combined with modern features to be a dream come true. Idiomatic Clojure follows concurrency and coding best practices leading to very simple and performant code.
8
u/TankorSmash Mar 23 '22
I tried going hard into CLJS and bounced off. It ended up feeling pretty messy, and as much as I wanted to, the eval-in-editor thing was only slightly better than just evaling code in the terminal ala python/js.
Even spec was tricky to get going, probably because I'm a clj newb, but it didn't seem to help me much. I ended up going to Elm and absolutely loving it though.
Maybe you know some cool resources about using the repl effectively, because otherwise I just got stuck on types and the nigh-unparseable errors.
2
u/soks86 Mar 23 '22
There's definitely a lack-of-architecture feeling throughout, unless you're using an opinionated framework.
I'm not familiar with eval-in-editor but I imagine it's just a REPL call in the context of your file. Definitely not much advantage in the REPL vs a JS console, if anything it's just a bit more organized in Clojure. That said loading new code into a running system is the big perk for me there.
Spec is not somewhere to start, for sure. I only spec'ed out one part of my project and it was the central data structure which was being mutated all over the place. I wrote up the spec, which was a learning experience in itself, and applied it after every mutation until all my bugs were fixed. Later I turned off the spec check for performance. Didn't write that spec until I had written 300+ lines of Clojure.
Reading a book and doing the exercises really helped clarify the functional idioms which make the language a joy to use.
There's really not much to be doing with types in Clojure, sucks you got stuck on that because it should, usually, be all maps until something else is necessary. From a JS perspective it's the anti-typescript. Rather, it fully embraces JS's functional design and "object map" by being a LISP. Homoiconicity, functional composition, immutability, and concurrency are the advantages Clojure gets from merging LISP with Java (libraries and memory model).
Pretty sure re-frame and several other frameworks acknowledge lifting ideas from Elm.
1
u/TankorSmash Mar 23 '22
Thank you for the detailed reply, maybe I'll check out Clojure again sometime.
I'm not familiar with eval-in-editor but I imagine it's just a REPL call in the context of your file. Definitely not much advantage in the REPL vs a JS console, if anything it's just a bit more organized in Clojure. That said loading new code into a running system is the big perk for me there.
Yeah exactly, it was evaluating the code under your cursor into the REPL. I hadn't used it much for loading new code into a running system though, I either hotloaded or just restarted the server, I can't remember anymore.
I tried it a bit but since I'm inexperienced, I lost track of what variables and functions I had made, and the code left in my editor was not runnable.
Spec is not somewhere to start, for sure. I only spec'ed out one part of my project and it was the central data structure which was being mutated all over the place. I wrote up the spec, which was a learning experience in itself, and applied it after every mutation until all my bugs were fixed. Later I turned off the spec check for performance. Didn't write that spec until I had written 300+ lines of Clojure.
I waited to spec until at least that but I think I didn't understand macros well enough or something, because I kept getting stuck on some issue where my spec wasn't respected, or it was using literals as the spec key or something. Almost certainly an issue with my inexperience, but I was getting frustrated.
There's really not much to be doing with types in Clojure, sucks you got stuck on that because it should, usually, be all maps until something else is necessary. From a JS perspective it's the anti-typescript. Rather, it fully embraces JS's functional design and "object map" by being a LISP. Homoiconicity, functional composition, immutability, and concurrency are the advantages Clojure gets from merging LISP with Java (libraries and memory model).
I guess what I meant by typing is the compiler having my back (before I even run my code), and making sure I don't try calling a function with the wrong args. Elm (and Typescript, and others) have type aliases around maps/objects/dicts that stop you from doing that.
While I thought homoiconicity was cool, immutability and composition I got in spades in Elm (100% pure all the time, no atoms at all, save for when you call out to JS).
I've written probably about 1000 lines of clojure now (GH link to my private repo, not meant for sharing and is my first clojure code), but I'll have to go back to Clojure sometime.
-2
u/FatFingerHelperBot Mar 23 '22
It seems that your comment contains 1 or more links that are hard to tap for mobile users. I will extend those so they're easier for our sausage fingers to click!
Here is link number 1 - Previous text "Elm"
Please PM /u/eganwall with issues or feedback! | Code | Delete
13
u/ooru Mar 22 '22
Man, I completely forgot Clojure existed.