Weeknotes 2023 W19: Stub
A mostly uneventful week.
Next week’s weeknotes will likely be shorter than usual, as I’m on holiday, traveling, and won’t be too focused on writing stuff down. I travel for the in-the-moment experience, not for generating content to share.
A few quick bits:
-
I had my last dentist visit for a while (hopefully). The fillings are in place and I promise to take good care of my teeth so that I don’t have to go back to the dentist any time soon (except for a check-up, maybe).
-
I cleaned my windows — finally. It wasn’t difficult and didn’t take a lot of time; it was really just the inertia holding me back.
-
Seen on the street: graffiti that says to delete dead people from your phone’s address book. The graffiti isn’t wrong, but I wasn’t ready for any graffiti to hit this hard.
-
I bit the bullet and bought Valkyrie, a typeface that has been on my wishlist for quite a while. I’ve updated my web site to use it. I think it looks quite pretty. Let me know what you think?
I’ve attempted to give Siri a try on my iPhone, but I’m really not a fan. Perhaps I’m not using it properly.
In my last interaction with Siri, I said “Hey Siri! Can you — ” before being interrupted by Siri. I instinctively replied with “stop interrupting me!!!” and then Siri showed me a link to a web page about the psychology of interruption.
The whole thing was remarkably passive-aggressive.
I signed up for another acting course. This one is for beginners as well, but there are follow-up courses available, which creates a path forward for me. It think it’ll be quite different from the Chekhov course that I’m already taking, focusing on script analysis and character creation, which are skills I want to obtain.
Getting out of my head and into my body is wonderful. I’ve certainly got the tendency to (over)think everything in life, which isn’t helpful for acting. It’s great to have something regular to do that is so vastly different from what I typically do.
Self-published books are on the rise, and I’m not sure that is a good thing. A handful of the books that I’ve recently bought were self-published, and the quality varies so greatly. All of them have problems — some small, some big:
-
Some books use small caps, but don’t use a typeface with proper small caps, rather using capital letters that are set at a smaller font size. This is jarring because of the difference in font weight. Compare:
-
Images are often a problem. The printed books often use raster images rather than vector images, which ends up looking awful. Another problem that I see often is that the font size of the text inside the images is often mismatched with the body text size, sometimes being so small to be unreadable.
-
The layout of some books is broken. The right-hand side (recto) needs to have an odd page number. New chapters need to start on the recto page (if you want to be consistent about it), not the verso page.
-
Headers are so useful for non-fiction books to make it easy to navigate. Add at least the chapter title to the headers, and consider adding the section title as well. A non-fiction book with only page numbers is impossible to navigate without continuously referring to the table of contents.
-
Some books miss oh-so-useful structural components. I’ve seen books with no preface, no introduction, and no index. Not every book needs these, but there are books that need them and don’t have them.
-
Some books have weird page numbering, starting with decimal numbering right from the table of contents, not distinguishing between front matter and main matter.
-
Lastly, some books have grammar and spelling mistakes, which I find incredibly off-putting.
This is why publishers exist.
Am I being nit-picky about all this? Perhaps a little. But reading a well-designed, carefully-crafted book can be such a joy. The exact same content, when presented in a less-than-great format, can yield a boring or even frustrating experience.
If you’re thinking about self-publishing a book, get in touch with me so I can help you avoid the biggest mistakes. I’m gladly offering you my assistance. But I think my general recommendation, if you care about quality at all, would be to find a publisher and not to self-publish.
At work, the topic of stubbing and mocking has come up again, in particular because one team was about to codify a standard for stubbing/mocking in which as much is stubbed out as possible for pretty much any type of test. I said “nooooo” and told them of my view on stubbing, which is that stubbing is, in my opinion, a last-resort solution only.
I want to illustrate this with an example, which inserts a given Thingy
into the database if it does not yet exist:
class InsertThingyIfNeeded
def initialize(attrs)
@attrs = attrs
end
def call
return if FindThingy.new(@attrs).call
InsertThingy.new(@attrs).call
end
end
class FindThingy
def initialize(attrs)
@attrs = attrs
end
def call
# …
end
end
class InsertThingy
def initialize(attrs)
@attrs = attrs
end
def call
# …
end
end
The code itself isn’t too important. More interesting are the tests.
The tests for FindThingy
and InsertThingy
are straightforward: they use the database and don’t stub anything. But the story for InsertThingyIfNeeded
is different: the standard approach at my employer is to mock any other service-like class, i.e., mock FindThingy
and InsertThingy
. In practice, it looks like this, in pseudocode:
describe InsertThingyIfNeeded do
let(:find_thingy) { stub }
let(:insert_thingy) { stub }
before do
allow(FindThingy).to receive(:new)
.and_return(find_thingy)
allow(InsertThingy).to receive(:new)
.and_return(insert_thingy)
end
example do
InsertThingyIfNeeded.new(attrs).call
expect(find_thingy).to have_received(:call)
expect(insert_thingy).to have_received(:call)
end
end
The last few lines are the ones I want to highlight. These are the lines that verify that find_thingy
and insert_thingy
both received #call
. It’s my belief that such tests aren’t really useful, and more importantly, are quite brittle. If FindThingy
or InsertThingy
ever change, then the stubs in the test will need to be adjust — but probably won’t — because the old tests will keep on passing, even if the actual method calls would cause them to fail.
The issue here is that the test suite contains only unit tests, and no integration tests. All three classes are tested in isolation, but are never tested together. All the tests could pass and test coverage could be at 100%, but the code could still be broken.
All this leads me to the question: what is the use of stubbing? I personally avoid stubbing if at all possible, and resort to it only if there’s no reasonable alternative. I am generally OK with stubbing HTTP requests (with Webmock) and the filesystem. Stubbing can also be useful to speed up tests, but there then needs to be at least one integration test, where nothing is stubbed. You’ve got to test the full path at least once.
Entertainment:
- I’m continuing in House of Leaves. It’s all the entertainment I need.
Links:
-
Ancient Therapy for Modern Problems: Stoic Philosophy Explained (Philosophy Tube): Interesting! I wrote about stoicism a few weeks ago, in Weeknotes 2023 W16: Envy.
-
VESPER: Mirror’s Edge (Official Video): Good music!
-
We’re Not Remaking Horror Games, We’re Chasing Nightmares (Jacob Geller)