One line of ruby!
def repl
loop{ puts eval $stdin.readline }
end
12,000 lines of ruby!
require 'pry'
binding.pry
REPL-driven development
- Don't write code first.
- Don't write tests first.
- Use the REPL first.
P(bug)
- When you write code: ~0.8
- Github production: ~0.000000008*
* Github exception-% this week is 0.0008%,
assume 1000 method-calls per request.
100,000,000 times better?
- Run the code → 1000 times better?
- Read the code → 100 times better?
- Understand the code → 1000 times?
100,000,000 times better?
- Run the code → takes seconds?
- Read the code → takes minutes?
- Understand the code → takes days?
Pry
- Easy to run the code!
- Easy to read the code!
- Helps to understand the code...*
* Though I usually git clone if I need this.
Recap
-
ls shows methods.
-
$ (show-source) shows code.
-
? (show-doc) shows documentation.
Downsides of REPL
- Doesn't keep a record.
- You have to re-test lots.
- Hard to test large apps.
Solution: Tests
Find solution in REPL.
Record findings in tests.
Write code that works first time :).
Tests help
- When code-base is large.
- With API design.
- Document assumptions.
Downsides of Tests?
- Slow to write.
- Slow to run.
- Go out of date.
Pry can help!
- gem install pry-plus
- require 'pry-rescue/minitest'
- require 'pry-rescue/rspec'
Recap
- try-again
- break
- step / next
- play
- edit
Even with testing
- Bugs slip through.
- Become harder to catch.
- Require longer to debug.
- Catches exceptions in production.
- Captures data to help you debug.
- Notifies you intelligently.
Fixing bugs
- Reproduce locally.
- Find problem.
- Fix it.
Recap
- binding.pry
- cd
- up / down
- whereami
- help
Use a REPL
- Saves time
- Improves quality
- More fun!
Use Pry!
- Featureful
- Robust
- Friendly