Episode 012: Embrace the REPL
Christoph complicated development by misunderstanding the REPL.
- We go back to the roots of Christoph’s experience with Clojure…
- How do I run Clojure code?
- The REPL is fun for evaluation, but how do you run a “real” program?
- Experience in other languages: edit the file, compile, rerun the program
- Mentality: get through the edit, compile, run loop as fast as possible!
- Autobuilder is the logical end.
- “Where’s my autobuilder in Clojure?!”
- The REPL model is fundamentally different.
- “[The REPL] is like cutting the Gordian Knot. You change the problem and that’s how you solve it.”
- “The reason why the problem I wanted solved, wasn’t ‘solved’, is because nobody has that problem because they do things differently here.”
- Tactic 1: edit, save, restart the REPL
- “Restarting the REPL isn’t super slow, but let’s just say it’s not instantaneous.”
- Tactic 2: edit, save, run
(use 'the.namespace :reload)in the REPL
- “Now I have a REPL history of
- forgetting to reload dependent namespaces
- loading dependencies in the wrong order
- old definitions built up
- Big Problem: function renames left the old version around, so accidental calls using the old name produced no errors and ran old behavior!
- Back to quitting the REPL to clean out the cruft. Ugh!
clojure.tools.namespace! Reloads everything and cleans out the cruft!
- Tactic 3: edit, save,
(use '[clojure.tools.namespace.repl :only (refresh)]),
refreshwould purge itself!
- “I don’t know why it took me so long to discover the magical
- The REPL will automatically
- “I can put code into a
usernamespace and it will be there for me.”
- Christoph would switch namespaces in the REPL without even stopping to wonder what namespace he started in.
- “It’s like walking out of a door and not even thinking about the fact you’re in a building. Oh wait! What room did I just leave?”
- Tactic 4: make sure
refreshis in the
usernamespace, edit, save,
- However, Christoph still didn’t understand the REPL.
- Just thought the REPL was for:
- reloading the code and restarting
- evaluating snippets of code
- inspecting stuff
- Nate’s big ah-ha moment: “Not only is my application inspectable, it’s fungible. I can change it in place as it’s flying along! I don’t have to restart it!”
- Christoph’s hint that there was still more came from seeing
commentblocks in code and reading about vim-fireplace.
- “There’s a new room you can explore. That room is editor integration with the REPL.”
Clojure in this episode: