Christoph gets some work done by fiddling around.
- Editor integration is a massive change in how to use the REPL.
- Put a
comment
block right underneath a function you are working on, and invoke the function with test arguments.
- Can quickly make changes to code and try it out--all in the same place!
- Problem: comment blocks littering the code.
- "A good rule of thumb I've found is: when I have to use the world 'careful', it's a big red flag. I'm doing something I should be able to prevent without having to be careful."
- Code in
comment
blocks can be helpful in the future.
- "'It's not done yet." What file is ever done? You're always going to come back to it in 6 months."
- Easy to skip around between forms you've run before.
- "It's like a random access REPL history."
- Ah ha moment: make a separate file for the helpful
comment
blocks.
- "[The comment blocks] are like the copilot of my development experience." "They're me helping me!" "You're your own copilot!"
- Separate file needed a namespace: the
fiddle
namespace was born.
- "I'm just fiddling around."
- Put the "fiddle files" in the
dev
tree so it only gets loading in development.
- "These fiddle files started multiplying, like little helpful rabbits."
- Like pages in a notebook centered on a theme. Each "page" is a file:
- a file for remembering how to call certain core functions
- a file for experimenting with date and time conversions
- a file for exploring a new concept
- a file for interacting with new code being developed
- Never have to leave to editor. REPL is working behind the scenes.
- Unlike REPL history, you can share fiddle files.
- Fiddles can help show the developer's mindset during development.
- "It's like seeing into the back of your mind of the way you explore this on your own."
- Example: exploring a data set
- work on code for parsing a data file
- write different expressions to sift through the data
- e.g. threaded expression to: open the data, parse it,
filter
, and map
- build up helpers for making sense of the data
- parser and helpers in fiddle are the start of the "real" application code
- write examples with commentary
- Example: exploring the working state of the application
- set of utility functions for grabbing information from
component
- that set of helpers can be share between developers
- code that pulls out state from specific components all at once
- "Where did this
nil
come from?"
- Example: exploring external APIs
- write simple function for calling the HTTP endpoint
- start calling it with different examples
- can easily see and re-run calls that you've tried
- Slow API? Use
(def response (...))
to save a result, and write expressions using response
.
- "A fiddle file like a scratch pad for new features."
- Characteristics of fiddles
- a working set of expressions
- like a notebook with code around a theme
- like a scratch pad for exploring toward a solution
- can be shared
- written context from solving the problem
- "The me of the future won't have as much access to the mental state of the me of the present."
- Do your future self a favor and write down some of your current mental context.
- Could make educational fiddles for new developers in a project.
- "Fiddles are a way of capturing process: a way of capturing the craft of making it, not just the outcome."
Related episodes:
Clojure in this episode:
comment
def
, defn
->
, ->>
filter
, map
, reduce
select-keys
clojure.pprint/
Related projects: