Mailing List Archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [tlug] Constructed state, unit tests and REPLs

On Thu, 3 Sep 2020 at 07:43, Curt J. Sampson <> wrote:
On 2020-09-03 06:49 +0200 (Thu), Josh Glover wrote:

> I've used the GHCI REPL a little bit, but I'm certainly not an expert user,
> so I may be wrong here, but it isn't possible to reload code without losing
> your state, is it?

Sure, but if you've changed your data structures the old state isn't valid
anymore, anyway.

In Clojure, you're mainly dealing with maps, so there's not much changing of data structures happening. ;)
> The way I use a lisp REPL... often means executing code to build some
> state, then being able to evaluate forms in the context of my running
> program to try things out and develop my code incrementally....

Well, your unit tests also have to build that state, so if you want a chunk
of state that's a bunch of work to construct, you can just call the unit
test function that builds that.

I write veeeeeery few unit tests these days, since REPL-driven development frees me from the test-driven development that I found extremely useful in languages like Java and Scala.

I mainly develop the functions, write property-based tests, and then write a few example-based tests (AKA unit tests) for public functions to show people the intention of the functions and how to use them. I also document public functions, unless the function and argument names are so obvious that documentation would just be restating what's already there. ;)
In fact, this is why I generally don't use REPLs at all (except for looking
up documentation) in languages like Python: it's usually easier and faster
to write or tweak a test that does whatever little experimentation I want
to do than to type it in by hand into a REPL. (It's definitely a lot faster
the _second_ time I want to run it.) The same goes for things like
examining intermediate state: just whack a `print` into your function and
look at what the output is.

I use the ipython REPL quite a bit when developing Python, and find it fairly decent for the way I want to work, but the Emacs integration isn't there to let me quickly evaluate code and keep going. I lean heavily on ipython's history search.

It sounds like we have fairly different ways of working, which is not really surprising.
One reason for this would probably be that comprehensive unit testing
became widely known only after the "test it by hand in a REPL" technique
had been long established, so certain techniques have yet to be generally
updated to fit into this new world.
It would be cool if we lived in a world where you and I could sit side by side and hack code, because it would be genuinely interesting for me to see how you work. I really enjoy watching experienced developers work. :)


Home | Main Index | Thread Index