Test-Driven vs REPL-Driven Development

Reflections on the advantages of a TDD and REPL based approach to software development

REPL-Driven development is all about moving fast with rapid iterations towards the goal.
function assemble(t::Thingy, d::Doodad, s::Stuff)
bolts = get_bolts(HEX, 4)
goo = get_glue(SUPER)

gizmo = put_together(flip(t), s, bolts)
tighten!(gizmo)

doohickey = glue(gizmo, d, goo)
dry!(doohickey)
if isfaulty(doohickey)
throw(AssemblyFailed("Faulty parts, buy new ones!")
end
return doohickey
end
function assemble(t::Thingy, d::Doodad, s::Stuff)
bolts = get_bolts(FLANGED, 10)
goo = get_glue(EXPOXY)
gizmo = glue(t, s, goo) # wrong assumption on input/output
dry!(gizmo)
doohickey = put_together(gizmo, d, bolts)
tighten!(doohickey)
return doohickey
end

The Test-Driven Approach

const thing = Thingy()
const dud = Doodad("qwerty")
const stuff = Stuff(42)
@testset "Test if valid object created" begin
gizmo = assemble(thing dud, stuff)
@test !isnothing(gizmo)
end
function assemble(t::Thingy, d::Doodad, s::Stuff)
return Gizmo()
end

A Problem with Test-Driven Development

(LittleManComputer) pkg> test
Testing LittleManComputer
Status `/private/var/folders/n7/v31m12_x6lj1qpqrbsg7ln300000gn/T/jl_73BcOb/Project.toml`
[c742fd3c] LittleManComputer v0.1.0 `~/Development/Julia/LittleManComputer`
[8dfed614] Test
Status `/private/var/folders/n7/v31m12_x6lj1qpqrbsg7ln300000gn/T/jl_73BcOb/Manifest.toml`
[c742fd3c] LittleManComputer v0.1.0 `~/Development/Julia/LittleManComputer`
[2a0f44e3] Base64
[8ba89e20] Distributed
[b77e0a4c] InteractiveUtils
[56ddb016] Logging
[d6f4376e] Markdown
[9a3f8284] Random
[9e88b42a] Serialization
[6462fe0b] Sockets
[8dfed614] Test
Assemble mnemonic: Test Failed at /Users/erikengheim/Development/Julia/LittleManComputer/test/assem_tests.jl:45
Expression: assemble_mnemonic(["ADD", "12"]) == 111
Evaluated: 112 == 111
Stacktrace:
[1] top-level scope at /Users/erikengheim/Development/Julia/LittleManComputer/test/assem_tests.jl:45
[2] top-level scope at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.5/Test/src/Test.jl:1115
[3] top-level scope at /Users/erikengheim/Development/Julia/LittleManComputer/test/assem_tests.jl:41
[4] top-level scope at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.5/Test/src/Test.jl:1115
[5] top-level scope at /Users/erikengheim/Development/Julia/LittleManComputer/test/assem_tests.jl:5
Test Summary: | Pass Fail Total
All Tests | 56 1 57
Assembler tests | 35 1 36
Symbol table | 8 8
Instruction set | 10 10
Regression test | 9 9
Assemble mnemonic | 8 1 9
Disassembler tests | 11 11
Simulator tests | 10 10
ERROR: LoadError: Some tests did not pass: 56 passed, 1 failed, 0 errored, 0 broken.
in expression starting at /Users/erikengheim/Development/Julia/LittleManComputer/test/runtests.jl:4
ERROR: Package LittleManComputer errored during testing

REPL Driven Development

julia> 2 + 3
5
julia> length("hello")
5
julia> map(sqrt, [9, 16])
2-element Array{Float64,1}:
3.0
4.0
julia> t = Thingy()
Thingy()
julia> d = Doodad("qwerty")
Doodad("qwerty")
julia> s = Stuff(42)
Stuff(42)
julia> bolts = get_bolts(FLANGED, 10)
10-element Array{FlangedBolt,1}:
FlangedBolt()
FlangedBolt()

FlangedBolt()

julia> goo = get_glue(EXPOXY)
EpoxyGlue()
julia> gizmo = glue(t, s, goo)
ERROR: MethodError: no method matching glue(::Thingy, ::Stuff, ::Glue)
Closest candidates are:
glue(::Gizmo, ::Doodad, ::Glue) at sticky-stuff.jl:538
julia> gizmo = glue(d, goo)
Doohickey(1331)
julia> 5 ÷ 2
2
julia> 5 % 2
1
gizmo = put_together(flip(t), s, bolts)

Rapid Iteration in Context

julia> camel_case(s) = join(uppercasefirst.(split(s, '_')))
camel_case (generic function with 1 method)
julia> camel_case("hello_how_are_you")
"HelloHowAreYou"

How Does This Scale?

Objections to non-TDD Based Development

Fundamental Issue — Reading is Easier than Writing

The Power of Prototyping and Iteration

The Intentions of My Advice

Geek dad, living in Oslo, Norway with passion for UX, Julia programming, science, teaching, reading and writing.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store