3 ms·
I hear near universal praise for repl development but in my very limited experience with it, found it nearly impossible. Maybe someone can clarify? What I saw
by user3939382 4y ago
I hear near universal praise for repl development but in my very limited experience with it, found it nearly impossible. Maybe someone can clarify?
What I saw was that the repl leads to a runtime state that is invisible and therefore hard to predict. For example, you define a function in the repl, or assign a value to a variable. You’re just supposed to keep the existence of those declarations in your head? I must be missing something.
- Borkdude 4y agoIn Clojure, you don't typically type code into the REPL, but write code in a file and then evaluate that code in a REPL connected to your editor. We don't just type into a console window, then reboot for some OS updates and forget about our previous efforts :). Combining this with a static analysis tool / linter like clj-kondo will also help since it will remind you that you removed certain functions, while they may still be there in the REPL.
- nlitened 4y ago> What I saw was that the repl leads to a runtime state that is invisible and therefore hard to predict I'd also add to what Borkdude said: it also helps that Clojure strongly encourages you to keep runtime state localized (not spread all over the places).
- nanomonkey 4y agoIn the case of Clojure and many other Lisps one makes changes to your source code, and evaluate each one of those changes automatically, or through some key command (ie highlighting the s-exp and evaluating it directly). This allows you to hot reload changes to the source code, or fire off events directly from your editor. In Clojure one often has commented out code that one can test functionality, or make state changes directly. Very little work is done at the REPL command line, instead it is fired off to the nREPL (network accessable REPL).
- TacticalCoder 4y ago> For example, you define a function in the repl, or assign a value to a variable. You’re just supposed to keep the existence of those declarations in your head? If you're using a LSP server, which btw uses the "clj-kondo" which borkdude mentioned, it's totally independent from the REPL and will tell you immediately if your source file is missing a function definition or a variable. Now it could be argued that you could have a wrong version of a function declared in the source file (and hence LSP / clj-kondo would still be happy) while the correct version got only defined at the REPL but... That's not how I develop: typically I test stuff at the REPL but only define my functions in the source file. And from the source file, I "eval" the function and its hence available directly in the REPL. Now I don't know about others but in my case I regularly write anonymous functions at the REPL, which I test directly on some data at the REPL, and then I copy/paste the anonymous function to the source file and give it a name there. REPL> ((fn [x] (* x 2) 21) 42 OK, good, it works now, I cut/past (fn[x] (* x 2)) to the source file and change the anonymous fn to a defn. But I'll also sometimes just directly write the function in the source code file. In addition to that, unit tests can help too. So it's REPL + unit tests + LSP (which uses clj-kondo) and all three are totally independent. And yet although they're independent, when LSP tells me something like: "Function x is called with only argument but expects two", I can fix it, eval the correct function, and the REPL is immediately aware of the correct version. I've always got both the REPL and the Clojure LSP server running, independently, simultaneously. > or assign a value to a variable. Clojure really tries to put the emphasis on functional programming so you don't typically have lots of mutable variables to juggle with. I'd say I have more of a "global application state" at the REPL than different variables. > I must be missing something. Maybe you're simply not aware that you can code in the source file, eval there, and the eval'ed functions are directly available from the REPL? I'm not sure my explanation are very clear but I hope it helps.