Mailing List Archive

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

[tlug] Constructed state, unit tests and REPLs

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.

> 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.

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.

The main reason I used the REPL a fair amount when coding in Haskell was
that I had so few unit tests. :-)

> Again, this might be just a case of the poor craftsman (me) not
> understanding how to use his tools... ;)

Well, you _could_ describe it that way, but I don't think it would be a
particularly fair description. It would be better to say that there are
other techniques to do many of the things that developers currently do in
REPLs, but those techniques simply aren't as well-known or widespread.

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.

Curt J. Sampson      <>      +81 90 7737 2974

To iterate is human, to recurse divine.
    - L Peter Deutsch

Home | Main Index | Thread Index