Stop Typing Into REPLs
Help me help you
When I’m at someone’s desks, in person or virtually, it drives me crazy to see the heroics of typing everything in a REPL…
Let alone trying to manually fix broken code on in a REPL…
Or losing their work when exiting the REPL, and trying to grab fragments from the scrollback 😿
It doesn’t have to be like this…
REPLs aren’t perfect…
I ❤️ REPLs and they have great features:
- interactivity (including control of evaluation and tab-completion)
- feedback speed
but they also have drawbacks, YMMV:
- no syntax highlighting
- poor keyboard editing – probably Emacs-style shortcuts
- poor history – since session began; up/down arrow
Since text editors are becoming more interactive (i.e. like IDEs), and computers are generally becoming faster, the advantages of using a REPL have been decreasing over time. It seems common to settle for “whatever, I’ll just run the code…”.
But what if you could have both?
Mixed mode environments
The most obvious example might be a Jupyter notebook
You mix code cells and their results (whether text, number, graph) and weave, step-by-step, a report/presentation. If you’ve ever used a Jupyter notebook, or seen someone use one, you can see how powerful and liberating it can be.
But, if you’re willing to accept it, Microsoft Excel is probably the embodiment of an interactive programming environment:
Excel formulas are the world’s most widely used programming language.
And while these environments might be blissful for specific tasks, they certainly are not general purpose…
Turning EVERY REPL into a “Jupiter notebook”
We already have everything we need:
- a REPL – any REPL will do
- a text editor
the REPL does what it’s good for (interactivity, speed, …) and the text editor can focus on its strengths:
- great editing
- syntax highlighting
- organising, formatting, saving text
What’s missing? You need a way to “send text from the text editor to the REPL”.
Good news if you’re using vim, that’s already available: vim-slime
(disclosure: I am the author of vim-slime)
You end up with sessions that look like this:
- vim on one side
- R, or another REPL, on the other side
- graphs can pop in another window (this one opened by R)
I usually keep my eyes in vim, unless some error message shows up on the right.
What do I use vim-slime for?
From memory, I’ve used vim-slime with:
- node (javascript)
- elm
- irb (ruby)
- python
- iex (elixir)
- R, R markdown
- octave
- mysql
- psql
- sqlite
- even shells! (fish, bash, zsh)
I haven’t found a REPL where it wasn’t advantageous to “wrap” in vim-slime.
It doesn’t have to be vim-slime…
I understand that vim isn’t for everybody. The other good news is that vim-slime isn’t complicated … most of the work happens when “shelling out”. I don’t see why your favorite text editor couldn’t support this type of workflow.
If you find compelling non-vim alternatives, email me and I’ll include them on this page for others to find.