6 ms·
"Ok the app works now!" 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
by delegate 10y ago
"Ok the app works now!"
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.
- cygned 10y agoI am familiar with the concept of Clojure's reply but I am always wondering how one gets code out of it eventually.
- jeremiep 10y agoYou don't get code out of the REPL. You evaluate your code inside the REPL, often directly from the source files. 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.
- cygned 10y agoThat is the workflow I currently use, too. Luckily, Leiningen reloads most of my changes. I wished, though, there was the ability to save the current name space from the REPL. Hacking together a couple of functions and save their definitions when you're happy.
- dustingetz 10y agoThat's inverted I think. For JVM clojure I am always editing inside a .clj file, all the scrap goes in (comment) forms in the file and I send forms to the repl from the file. I rarely actually type in the repl.
- jeremiep 10y agoSame here, I only type at the REPL what I don't mind to lose after a reboot. Everything else is in *.clj/s/c files.
- dualogy 10y agoIn a number of languages with a number of editors / editor plugins, with a code file open I can easily keep open in parallel a REPL window/tab that has the code file (and libs/pkgs/modules that it imports) loaded in interpreted mode and can reload either on save or if that isn't hooked up, certainly by a repl command like `:reload` in GHCi which I use in SublimeHaskell. Marvellous "live-coding" experience of sorts. Works particular well when writing pure functions (same in = same out, every time, no side-effects etc) and in a language where quickly defining some temp vars for passing some random test arguments in a swift non-verbose manner is a total non-issue
- ethagnawl 10y agoThere are many editor plugins/configs which will allow you to evaluate code from inside your editor. 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.).
- omginternets 10y agoYou should work in PR. I mean that as a compliment. You've managed to give a clear and intuitive understanding on exactly how it feels to write clojure, and it sounds really nice... 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?
- dottedmag 10y agoThe answer to 1&2 combined is "watch talks by Rich Hickey": https://github.com/tallesl/Rich-Hickey-fanclub https://github.com/tallesl/Rich-Hickey-fanclub Once the messages set in, any ClojureScript-specific tutorial will be a breeze.
- omginternets 10y agoWelp, I know what I'm doing with my Saturday! Thanks!
- Nihilartikel 10y agoI'm a recent clojure convert too (haven't used clojurescript much).. I have to say, the only thing that annoys me about it occasionally is its marriage to the JVM. It took a few months to get into it from a C++/Python/Go background, but now, hacking in other languages (maybe less so in Python) feels like sculpting while wearing oven mitts - needlessly tedious and overwrought. But, to make a unit test by coding the function, making a lovely structured literal of the input data, running the function in the repl, and then pretty printing the hand-verified output to paste in as the expected test result is just the least effort I can imagine for that kind of coding process. I'd count myself as happier if every language had as strong a system for printing and reading in data literals.
- aeosynth 10y ago> I have to say, the only thing that annoys me about it occasionally is its marriage to the JVM. Clojurescript can be hosted entirely in js; here's a repl: https://github.com/anmonteiro/lumo/ https://github.com/anmonteiro/lumo/
- yogthos 10y agoI'm also working on Node.js port for Ring https://github.com/macchiato-framework https://github.com/macchiato-framework that's fairly usable at this point.
- jiyinyiyong 10y agoWhy not Lumo?
- yogthos 10y agoI'm not sure I understand what you mean.
- delegate 10y agoOh yes, the JVM is a pain.. 30 seconds just to start the app is a tough sell for a naturally-speed-obsessed C++ coder like myself. 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.
- EastLondonCoder 10y agoVery nicely written, I have to say it sounds very similar to my experience using redux/react. Although there are some things like homoiconocity you don't get writing functional JavaScript I do feel the learning curve is much less steep than ClojureScript.
- dustingetz 10y agoI love the JVM repl experience from Cursive and emacs. But I've never come close to it from ClojureScript for browser development. Can you describe your repl capabilities and dump some links? (I am looking for a real repl experience like on JVM where the IDE is hooked into the repl and forms can be sent across individually and the app can be built up piecemeal without restarts. If this isn't what I want, tell me what I want. Figwheel doesn't seem to be it.)
- swannodette 10y agoI don't understand. The Figwheel REPL does exactly that + hot loading. I use Figwheel with Cursive - works great.
- dustingetz 10y agoCan you post a short video of your workflow? It might help a lot of people
- delegate 10y agoI'm not sure if this is the 'right' way to do it, but here's how I do it with Cursive (should also work with other editors): 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")
- unlogic 10y agoIn Emacs, you can use CIDER together with ClojureScript. By following these instructions[0] I was able to get the combined Figwheel+REPL functionality. [0] https://cider.readthedocs.io/en/latest/up_and_running/#using-the-figwheel-repl-leiningen-only https://cider.readthedocs.io/en/latest/up_and_running/#using...
- jbeja 10y agoSame with Typescript, never need to touch the browser, Types are enough.
- pka 10y ago> 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 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".
- sk1pper 10y agoI wholeheartedly agree it's easier to write clearer OO code after spending time writing in Clojure. 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.