by delegate · 9y ago · 0 comments
I say this after running the last command in the REPL - it's what I've been doing for the last 2 hours. I haven't looked at the browser since I started.
I switch to the browser and sure enough, the whole thing works perfectly.
This is the Clojure(script) experience - it's a different method of developing applications. Combined with the brilliant weirdness of the language itself, it sucks you into the REPL and persists even after you've finished coding.
The most suitable word for this experience is "hacking". You don't code your program, you hack it.
The only drawback of Clojure/Clojurescript is the high learning curve.
Maybe the 20 years of OO programming have really left a dent on my brain or maybe it was because of the young age of the ecosystem, or maybe because tooling wasn't quite there yet, but I found it quite a challenge, before I could write even basic programs.
Even now, after having spent months learning it, I still find it intimidating.
Oh and did I mention how much clearer it is to write C++ after learning Clojure ?
Pure functions, immutable data, data vs code.. just some of the concepts that help a lot when you bring them to an OO language.
I've used 'the JVM argument' to justify putting the language aside for a year or so, but now I'm back and it doesn't seem to bother me as much.
Why would it do that every time one compiles one's project? Surely Clojure must keep a cached linkable byte-code/binary somewhere per version/OS/arch, as all modern languages seem to do?
I invested a lot of time in learning clojure, but Oracle concerns me enough that I'd rather not build my knowledge stack on them.
So I've stopped using clojure. I may look into clojure script again in the future, but it still feels like a kludgey experience to me. Inspite of the amazing efforts by David Nolan and the community.
[1]: https://developers.redhat.com/products/openjdk/overview/
Clojurescript can be hosted entirely in js; here's a repl: https://github.com/anmonteiro/lumo/
So with respect to the high learning-curve, a few questions:
1. Were there any non-obvious concepts that you wish you'd understood going in? i.e. anything I can do to make my learning-curve shallower than yours?
2. Can you recommend any resources for getting started?
Once the messages set in, any ClojureScript-specific tutorial will be a breeze.
> I switch to the browser and sure enough, the whole thing works perfectly.
This is the general workflow in a typed language as well (i.e. PureScript, Elm) - you write some code and then fix the type errors in the editor - only that instead of running a couple REPL queries and just assuming that your app works, you really do have some hard guarantees in all edge cases, like no crashes, no type mismatches, logical coherency.
Most of the time this then means that the "app works".
1. In project.clj, add the nrepl port for figwheel: :figwheel { :nrepl-port 7002 }
2. Start figwheel with `lein figwheel` and open the page in the browser
4. In IntelliJ, Create a new Clojure REPL -> Remote, pick "Connect to server" and enter "localhost" and 7002 for port.
5. Start the REPL, it should connect to the figwheel repl, then type (cljs) and you should be in the ClojureScript repl.
6. Test that it works: (js/alert "Hello")
[0] https://cider.readthedocs.io/en/latest/up_and_running/#using...
But I think another drawback of cljs is readability. It's super cool that everything is data and data structures, but it makes it harder to eyeball code, just takes longer to parse and understand how these data transformations actually map to side effects on the page.
IMHO well written OO code is easier to understand and reason about.
For example I'll often write a function in a source file, evaluate it from there so it exists in the process, then call it from the REPL to test it works correctly.
When I launch the program, every temporaries made at the REPL are gone, but the source stays.
For instance, I use tmux/Vim/Vim Slime, which allows me to send code from the editor to the REPL (running in a separate tmux pane). This setup isn't as embedded or as fancy as some of the other options (e.g. Light Table). However, this setup doesn't force me to break my standard workflow and works with other languages which offer a repl or interactive console (e.g. Scheme/Racket, Ruby, Haskell, JS, etc.).