6 ms·
Why your REPL experience sucks
- PaulHoule 4y agoWorkspace-based programming environments have always struggled. When I use Jupyter I rerun the whole book pretty frequently. If the book takes 30 seconds to run it is a big annoyance but saves time relative to the randomly irreproducible problems I see other people have. If the book takes 3 hours to run it is a different story.
- all2 4y agoThe idea of "book" and the linear visual in a "book" limit the interaction of the user. What if, in addition to the "book", you had a visual representation of the environment? Further, what if you had a function application visualization? Say you start with with open(your_csv_here) as my_csv: ... some actions In the function application viz you'd see something like your_csv_here | open as | my_csv In the environment visualization you'd see two variables your_csv_here my_csv Ideally, you'd be able to grab either of those in the "book"'s linear representation of code blocks using auto-complete. --- When I've played with data sets in Pandas DFs, for example, having some awareness of my environment and the available states of data -- and how that data has been mutated -- would be extremely helpful. --- I've taken the view that a Jupyter notebook or similar environment represents a filter for one or more streams of data. Ideally, you need to be able to quickly visualize the execution environment and previous actions/filters applied to your data streams. I'll admit, this does nothing for working with logic (except that you'd be able to inspect inputs and outputs pretty quickly).
- nerdponx 4y agoFixing this situation is supposed to be the promise of "reactive" notebooks like Julia's Pluto.
- PaulHoule 4y agoThat's one answer to the problem, but not the only answer or necessarily a complete answer... That is, people forget that the really special thing about spreadsheets is not the grid organization but the hidden graph organization of computations. I would point to this as a product that was ahead of its time and still seems without peer https://en.wikipedia.org/wiki/TK_Solver https://en.wikipedia.org/wiki/TK_Solver Another challenge Jupyter has is the conflict between "a way to present a report" and "a way to write a script that generates a report" and everything in between.
- eigenspace 4y ago> That's one answer to the problem, but not the only answer or necessarily a complete answer... That is, people forget that the really special thing about spreadsheets is not the grid organization but the hidden graph organization of computations. Uh did you mean this the other way around or something? Reactive notebooks like Pluto only address the hidden graph organization of computations, they don't address grid organization at all.
- nikanj 4y agoWe keep on making fun of php, but it had this problem solved in the 90s. Hit F5 in the browser, get the latest version of your software. No waiting 30s for a rebuild, no stale versions in caches, no headaches.
- tonetheman 4y agoPHP was and still is great. Make a change and hit refresh. Simple and easy.
- cutler 4y agoThe Clojure repl allows you to eval changes within a live application. Try that in PHP and I don't think you'll get very far.
- cess11 4y agoWhat do you mean by "live application"? Is a PHP application under nginx "live" or not? If it is "live", changing a file will immediately be reflected in the application on the next "eval", i.e. require or execution by the interpreter.
- klibertp 4y agoNope. That's not what the GP means. I'm not sure how it works currently with PHP, but what was meant was a long-running process that can change its behavior/be updated by evaluating new code without ever being restarted. Think of it like this: you have a page that never stops rendering, ie. you send some HTML but instead of finishing processing, you go into an infinite loop. "Live" system, in that situation, would still be updatable - you could change the body of the loop and make it produce another bit of HTML, without reloading the page. Again, I'm sure modern PHP was already optimized far from the initial "execute all the code on each request" model, but unless there's a long-running process that can be updated in memory without restart (and I don't mean doing `exec` on itself, that's cheating!) - it's not "live" by this definition. It's not that clear-cut a distinction, either. For example Elixir and Phoenix are definitely live, in that there's a process that responds to requests on one hand, and can be updated without restarting it on the other - but page reload is still required in many cases, even if triggered via websocket. This idea of liveness predates both PHP and the Web by 2 decades at least and comes from Lisp and Smalltalk. It's been incorporated by Erlang and later Elixir, and by Clojure. Other than that, some embedded scripting languages support this kind of development, for example Awesome WM is scripted in Lua, and you can evaluate arbitrary Lua code while it's running. Emacs is another system that is meant to be used this way. Good to read: https://gbracha.blogspot.com/2020/01/the-build-is-always-broken.html https://gbracha.blogspot.com/2020/01/the-build-is-always-bro...
- markeibes 4y agoWhenver I use a REPL I'm annoyed I didn't write it as a test, so I get proper import completion and generally tooling support. Finally I usually want to reuse the code or have a regression.
- capableweb 4y agoI think you're thinking about a different type of "REPL" than what the author is referring to. What you're thinking about is more of a "Programming Shell", a separate window/tab/pane where you enter code and when you're happy, you copy-paste that into your source file. What the author is talking about is a REPL running in the background while connected to your editor. So most of the time, you're entering code directly into your file, while evaluating snippets in the REPL but you never leave the editor itself. With that approach, nothing is stopping you from using the REPL to write the tests themselves. In fact, that's what I tend to get the most value from, writing unit tests together with a background REPL, interactively building up the test case until I'm happy, then committing the unit test that has been written in the process.
- TacticalCoder 4y agoI really only ever encountered this issue when working with ring routes, as in TFA. Love the macro at the end, may start to use it because why not. Now I want to say this to Clojure beginners: launching Emacs with a very complicated, non optimized, init (3400 lines of custom elisp code I wrote over the years) takes 1.4s on my system. Now launching the app, with two REPLs (one for Clojure on the back-end, one for ClojureScript on the front-end I'm testing) and about 30 dependencies (including figwheel, which is kinda heavy) takes... 16 seconds. So, from complete scratch, launching Emacs, opening a Clojure source code file, (which btw also triggers the launch of the Clojure LSP server) and then launching the webapp server, two REPLs and loading the main webapp page in a browser takes less than 18 seconds. Well, ok, it's not from complete scratch as source files that haven't been modified do not need to be recompiled, I'll grant that. It's a 2019 AMD 3700X with 32 GB of RAM and a NVMe M.2 PCIe 3.0 x4 lanes SSD. Not a bad machine but not last gen either (I'm probably swapping it for a 7700X one of these days). I'm pretty sure the startup time is going to go significantly down when I'll switch to the 7700X. So even though it's great to not have to restart the app/REPLs it should not be a problem to restart the whole thing. If your REPLs take two minutes to start, I'd argue there's an issue and it's time to fix that first. Move from lein to deps.edn (which launches one JVM less, which really helps as Clojure startup times on the JVM are slow), buy a faster dev machine. Buy a PCIe SSD. Use chrome/chromium instead of Firefox for testing your webapp (in my experience chrome is simply way faster for anything JavaScript and, oh boy, does ClojureScript generate lots of JS). Etc. As a sidenote I'd say this specific "ring route not updated" is a variation of the age old issue of cache invalidation. So basically: I love working at the REPL and keep my REPL(s) opened for a very long time, hot reloading everything (including ClojureScript on the client-side) without needing to restart everything but I don't lose sleep over the fact that I do sometimes relaunch everything for it takes not even 20 seconds.
- jwr 4y agoA related question is why would you want to reload the entire file/namespace every time you make a change? Coming from a Common Lisp background, I am used to evaluating single forms/functions. I would sometimes re-evaluate the entire namespace, but that would be relatively rare. I switched to Clojure many years ago and followed the same workflow. Then ClojureScript and tools like figwheel came along and I was somewhat surprised to find that people admire the "auto-reload" functionality so much: save a ClojureScript file and all of it gets re-evaluated in the browser interpreter. I found this to be inefficient, somewhat annoying, and a big step back from evaluating exactly what you wanted to. My guess is that lots of those people never worked with a REPL where you eval single forms from the editor, so this auto-reload on each save seemed much better. But it isn't! And it creates its own problems, like the one the OP solves in the article.
- simongray 4y agoHot reloading is useful when you're making something related to a React-based UI, which you likely are close to 99% of the time in ClojureScript. I seriously doubt it has anything to do with a lack of REPL experience. I use a traditional editor-connected REPL 100% of the time in Clojure and 0% of the time in ClojureScript. I think most of us doing full-stack Clojure work like that.
- jwr 4y agoHow is it useful? I've been developing a React app for the last 8 years or so, and I'd much rather eval single functions rather than reload everything. I feel much better in clj and cljc files, where I am not forced to do that.
- kelseyfrog 4y agoI used hot reloading extensively when developing a roguelike in Clojure. It was incredibly helpful to have a tight feedback loop.
- aidenn0 4y agoFWIW, I just use C-c C-k with CL because it's easier. The standards lawyer in me also wants to point out that implementations are free to inline function calls that are in the same file as the function definition, but I'm not aware of any implementation that takes advantage of this, so that's rather academic.
- aidenn0 4y agoLeaving wrong explanation for posterity and to keep thread understandable. See everything after [edit] for corrected explantion This is an important distinction between (funcall #'foo ...) and (funcall 'foo ...) in Common Lisp as well. #'foo evaluates to the function named by the symbol foo, while 'foo evaluates to the symbol foo itself. So if you redefine the function named by the symbol foo any already compiled forms like (funcall #'foo) will still use the old version but (funcall 'foo) will use the new version. [edit] The above explanation is wrong; whenever #'foo is evaluated it will resolve to the current function slot for the symbol foo. Since the form (funcall #'foo) evaluates #'foo each time, it will naturally be affected by changes to the function-slot for foo. If you bind a variable to #'foo (like e.g. a route in a routing library as TFA does for clojure) then the evaluation happens when you bind the variable. See my reply to throwaway1x31 for a full example showing the difference.
- throwaway1x31 4y agoIn sbcl those two work the same.
- juki 4y agoThey don't. What aidenn0 said applies to all CL implementations, although with a small correction that it's not "any already compiled forms", but rather any variables/objects that already hold the value of `#'foo` that will keep pointing to the old definition. Compiled code calling `(funcall #'foo ...)` will get the new definition normally (unless `foo` is inlined).
- aidenn0 4y agoDerp, of course it does because (funcall #'foo) evaluates "#'foo" every time it runs. You need to bind (or assign) the value for it to actually show the difference: (defun bar () 3) (defvar *the-fn* #'bar) (defvar *the-sym* 'bar) (defun foo () (funcall *the-fn*)) (defun baz () (funcall *the-sym*)) Then at the REPL: CL-USER> (values (baz) (foo)) 3 3 CL-USER> (defun bar () 2) WARNING: redefining COMMON-LISP-USER::BAR in DEFUN BAR CL-USER> (values (baz) (foo)) 2 3
- uptownfunk 4y agoR Studio repl experience one of a kind, have never found anything that replicates it perfectly.
- mm007emko 4y agoI always preferred Matlab to R Studio, TBH.
- cpursley 4y agoI've only used a few REPLs so far but Ruby and Elixir are great (and I assume inspired by Lisp). I cut my teeth developing with REPLs and actually struggle a lot with trying to use language environments without them. Like, how can I just experiment and run a little one-of bit of code and data before starting the actual implementation? Or call and play around with the function I just wrote?
- onetom 4y agoHave a look at Fred0verflow's videos, for example: * https://www.youtube.com/watch?v=St0_jsPnGAw https://www.youtube.com/watch?v=St0_jsPnGAw - analyze some SO HTTP API responses * https://www.youtube.com/watch?v=TaazvSJvBaw https://www.youtube.com/watch?v=TaazvSJvBaw - transducers from the ground up I think they are great, crystal-clear examples of REPL-based development.
- cpursley 4y agoOh, I think you misunderstood. I'm literally in the Elixir repl all day every day and do know how I'd don't know how I'd manage without one.
- onetom 4y agoIf the Elixir REPL is like a Ruby, Python or Node.js "REPL", then we are not talking about about the same kind of REPL in this context. I suspect, that the Elixir REPL is more like the Erlang REPL, which might be the same kind as LISP REPLs, but I have no direct experience, I just saw Erlang REPL usage from John Hughes videos.
- runevault 4y agoI used to be a big REPL head, especially in my time with Clojure. But in recent years since most of my programming was c# I got away from thinking in REPLs. However these days I'm doing personal work in F# so I have access to the REPL again, I just keep not thinking to take advantage of it. I guess this is my reminder to use ALL the tools a language/environment gives me.
- cutler 4y agoThe kind of repl the author refers to is strictly Lisp-based. Your F# repl wouldn't be any different from a Python or Ruby repl and falls well short of the Lisp/Clojure repl experience which is based on the code-as-data feature of Lisps.
- runevault 4y agoI'd have to check and see, but I know at least some of the features overlap (for example f# lets you send a single function/etc to the repl and update the existing definition. However to the specific point he brought up, I'm not sure if anything like the var capture issue comes into play.
- cutler 4y agoThe difference between the Lisp REPL and other, Algol-based programming shells (Node, Python, Ruby etc.) is in the R which stands for Read. The Reader is unique to Lisp since Lisp syntax approximates to an Abstract Syntax whereas other language shells have to parse syntax as raw source code during this first stage. The Eval stage is also different with Lisps.
- deleted 4y ago[deleted]
- AceJohnny2 4y agoNon-Clojure user here (but with just enough Lisp experience to make a fool of themselves)... > When Clojure evaluates the symbol router [(an argument)] here, it goes through almost the exact same process as it did for the symbol +, but without checking if it’s a special form. It looks for the var in the current namespace that maps to the symbol router, dereferences it, _and saves the function object it retrieves as the first argument before evaluating the second argument_, and then calling the function that run-jetty evaluated to. Why does it save the resolved function object, which is an argument at that scope? That sounds counter-productive to the reloadable functionality. Is it a performance optimization? If anything, it demonstrates that reloadable code is inherently at odds with performance.
- jaccarmac 4y agoNo expert on Clojure semantics, but I'm pretty sure what's being discussed is common to almost all runtime environments. When you pass an argument to a function, the function doesn't keep track of the name of whatever you pass, it keeps track of the thing you pass. (A few languages bind late enough that you are essentially passing names during function invocation, but AFAIK not many.) The difference is that when you redefine a function in Clojure, you're not updating the memory location of the old function but updating the function that a given var (one of Clojure's synchronization primitives) points to. The var quote, then, is roughly the equivalent of passing a pointer, while the naked syntax is roughly like passing a dereferenced pointer. I find the "save" language in TFA a bit confusing.
- AceJohnny2 4y agoThanks, that makes it a bit clearer.