These days I'm trying to differentiate between tests where dependencies (used by the Code Under Test) can't (and shouldn't) be replaced by Test Doubles—inside the Domain layer¹—and those that are replaceable (Use Case/Application layer), where the concrete version of the dependency accesses hardware or I/O.
¹ These are almost always part of an Aggregate (graph of objects).
@jitterted I often tested the lower parts of aggregates in isolation, but not so much the upper part. If the dependency was complicated, I might test with a simpler or more predictable version.
Testability and fast feedback loops drive everything I do in creating software. (One could say just fast feedback loops, and testability follows, but without testability, long-term viability of continued fast feedback loops can easily be lost.)
One of the best things about live coding (and doing it enough to have a few people in the "audience") is that it raises my level of awareness of what I'm doing by being asked questions:
"Why aren't you refactoring after getting to TDD-Green?" or "Why didn't you extract that string into a variable?" or "Do you use Test Data Builders?"
If I was trying to "get work done", these questions would be annoying¹, but instead (especially as a technical coach/educator) they are More Valuable than GOLD!
One of the hardest things to do as an "expert" who is also a coach is to take what has become automatic and turn it into steps that can be taught to a non-expert.
¹ of course if I wanted to just get work done, live coding is not the most efficient way to go (tho it works really well for me despite the welcome interruptions.)
I need to hire (i.e., pay) someone who can clean up some Adobe Illustrator files, or possibly recreate them (which ever is better), so that I can more easily work with them to change their text, size, etc., as I need to. Right now they look OK, but are very difficult to modify.
An example is below. I had to extend the edges (bleed) for printing, but this is terrible if I need a digital version that looks correct.
Recommendations of folks who can do this (perhaps it's you?) and boosts appreciated. (And in case it wasn't obvious, this is for-pay work!)
I've been reflecting on LLM tools in IDES, like Sourcegraph's Cody and JetBrains's AI Assistant, and I think that they (and other LLMs targeted for code generation) suffer from the same problem:
The inability to FORGET.
Unless you have complete control over the data used to train the LLMs, you're going to get old solutions for problems that may not exist anymore, because languages, libraries, and frameworks eventually deprecate and remove code, come up with better (or worse, but different) ways to do things, etc.
It's a bit frustrating to get a solution that works, but is the "old" way of doing things (indexed for loop instead of a for-each, or instead of a stream). It's even worse when the solution worked 3 years ago, but no longer does, or worse is a mixture of modern and obsolete code, making it difficult to separate the two (LLMs are entirely based on "mixing", so this happens frequently).
I'm pretty sure the solution for these kinds of tools is to be trained on better (or at least more recent) data.
Finished the "Reset Timer" feature as well as adding sounds for "Pause" and "Resume" (that way you can hear when the timer is paused without having to look at it all the time).
With the help of a viewer, was able to DELETE the kludgey JavaScript code and let #htmx handle all of the work of playing audio. Sending an <audio> element over the WebSocket with autoplay worked as desired!
The whole reason that Premature Optimization is evil is that it can make the code (much) more complicated, when you might still be modifying it heavily (hence the "premature").
Get it to work.
And ensure it's what's needed.
Then look at optimizing.
(This is a general guideline: your context, of course, might require you to do optimization up-front, but then it's not premature!)
Using #htmx in my apps has let me turn the "no logic in HTML templates" all the way up to 11.
I am now very aware (and suspicious) of any logic being evaluated, or even things like string concatenation, being done in HTML templates.
I may have to write a tool to warn me (or fail a test!) if I start using th:if, th:unless, or anything that looks like a method call in my Thymeleaf templates.
Part of the inspiration was also removing tokenized parsing of HTML. So, instead of “get PHP out HTML” it was “get HTML out of PHP” - it’s basically just string concatenation. lol
Very little code (a few hundred lines), and should be easy to port without becoming a full-blown project. A stable and complete build. I haven’t needed to tinker with it for years.
Why? Because 3 separate times, I predicted how the test should fail, and it failed differently! They failed in the unexpected way because I had either written the test setup incorrectly, or misunderstood a library method¹.
Had I just looked out for a failing test, I would have started writing code to make it pass, and been disappointed that it didn't pass when I was done.
--
¹ Turns out Java's String.indent(4) normalizes line endings, meaning it will add a line ending to the last line, even if it didn't have one before! Surprise!
@jitterted I have always thought the circle diagram for #TDD sent the wrong message to new practitioners. Refactoring should always start and end in green. If you refactor and things go red you’ve done something else other than refactoring.
Well that was a bunch of wasted time because the Mac PDF Preview app is BROKEN when it comes to password-protected PDFs that limit things (for form-filling).
I filled out the form in Preview, but once I saved it, nobody could VIEW it without the original security password (that nobody seems to know).
Apparently this is a known issue, but Apple has yet to fix this 2+ year-old problem.
Had to open it in Adobe Acrobat, fill out most of it there, then "print" to a new PDF, and then finish the edits with that new PDF.
If you were thinking of ordering your own copy of JitterTed's TDD Game, I recommend ordering soon, as I'm running low on inventory (and won't get more for another month or so).
Get your copy (or multiple copies—saves on shipping) today at https://tdd.cards