My weapon of choice right now is vim-iced[0], which is a batteries-included VIM plugin that, in addition to providing a REPL and keybindings to evaluate expressions under the cursor, also allows me to auto-format my files on save.
My weapon of choice right now is vim-iced[0], which is a batteries-included VIM plugin that, in addition to providing a REPL and keybindings to evaluate expressions under the cursor, also allows me to auto-format my files on save.
For me that is the optimal way of doing things.
I want to restructure stuff, make multiple versions of functions, move them in and out of comment blocks or just leave code there for REPL use.
When I first saw someone writing Clojure like this on a video I was thinking: "This is the way I want to write code." I think this is the best of both worlds.
I think programming at the REPL requires a very different mindset from how a lot of us learned initially. The thought of leaving commented code in our codebase is one of those things we're told not to do, but there's a great snippet from one of Stuart Halloway's talks where he mentions "Rich Comments" (pun intended I think).
Rich is apparently known for leaving REPL code inside comment blocks specifically for testing purposes, and as a sort of transcript of the work that was done. [0]
Its a great approach, and one that I've adopted, but it seems wrong at first glance when taken out of the context of a REPL.
[0] https://github.com/clojure/clojure/blame/4ef4b1ed7a2e8bb0aaa...
For emacs users, 'eval-region' and 'eval-expression' are your friends.
Edit: I should have included a link for CIDER: https://cider.mx/
#+BEGIN_SRC lisp
(+ 1 2)
#+END_SRC
#+RESULTS:
: 3
(type C-c C-c inside the source block)If you use noweb it'll also include referenced blocks in the evaluated unit:
#+NAME: foo
#+BEGIN_SRC lisp
(defun foo (n) (+ 1 n))
#+END_SRC
#+BEGIN_SRC lisp :noweb yes
<<foo>>
(foo 2)
#+END_SRC
#+RESULTS:
: 3
This lets you have many versions of code in one file (if that's a sensible thing for you, very useful when exploring a new library or concept though), and in the end you can aggregate it all into one source file for sharing with others: #+BEGIN_SRC lisp :tangle foo.lisp
<<foo>>
<<bar>>
#+END_SRC
(type C-c C-v C-t to create the file)I've mainly used this (for interactive development) with Common Lisp, but it should work for most other languages that offer similar interactivity.