Mark Seemann
@ploeh.dk
160 followers 1 following 130 posts
Posts Media Videos Starter Packs
ploeh.dk
Other readers are showing their appreciation of ploeh blog by supporting it. You, too, can do that. blog.ploeh.dk/support
Support the blog
Ploeh blog is free, and always has been. Keep it free.
blog.ploeh.dk
ploeh.dk
This post, btw, rounded a corner of a sorts.
ploeh.dk
There used to be more 'engagement' in the past. People would repost, respond, or comment on SoMe (mostly Twitter), and believe it or not, add comments to the articles themselves.

There's not much of that left now. A bit, but noticeably less than a few years ago.
ploeh.dk
Thank you, that's good to hear.

To be honest, blogging increasingly feels like no-one's reading...
ploeh.dk
Not quite, but on the other hand, I currently don't actively seek conference appearance. I'll come if invited and we can agree on terms.
ploeh.dk
I've been reviewing some Python code that uses Result return types (via returns.readthedocs.io), and once more I refer to @eiriktsarpalis.bsky.social's excellent article 'You’re better off using Exceptions': eiriktsarpalis.wordpress.com/2017/02/19/y...
returns 0.26.0 documentation
returns.readthedocs.io
ploeh.dk
As things currently look, IT Days in Cluj-Napoca is going to be my only public appearance in 2025. www.itdays.ro
ploeh.dk
True. That, however, is not really my concern. Whether I have to edit 1 or 2 Repository implementations is a small problem compared to having to edit n tests. That's what I meant by O(1) edits versus O(n) edits.
ploeh.dk
While you wait for your work language to get discriminated unions: Your language already has discriminated unions. #repostfriday Visitor as a sum type. blog.ploeh.dk/2018/06/25/v...
Visitor as a sum type
The Visitor design pattern is isomorphic to sum types.
blog.ploeh.dk
ploeh.dk
If one were concerned about boundary cases, it might be reasonable to augment the test suite with some property-based tests, or perhaps even better, add mutation testing.
ploeh.dk
Why, however, didn't I discover that I also had to change my Fake implementation?

Because (being TDD artefacts) none of my tests were even close to that boundary.

Is that a weakness with TDD? You could argue that case.
ploeh.dk
The point of the example is that Mock-based tests are Fragile Tests. Abusing big-O notation, we can say that the cost of making the example refactoring is O(n), where n ~ number of tests.

Conversely, the cost with state-based testing is O(1). It doesn't really matter whether the constant is 1 or 2.
ploeh.dk
Yes, good point, and an astute observation that I didn't myself make. All tests passed, except the Moq-based test. I'll return to why that is in a moment, but I don't think it changes the argument; and neither does having to change the Fake implementation. That'll follow in the next post.
ploeh.dk
Look, I found a real-life Tron Recognizer ship!