Avoiding fakes, I'mo telegraph this, cuz so many have asked, but the truth is February is my personal ebb-tide, and as much as I wish I could lay it out at the primer level, I simply don't have that in me right now.
Start by knowing who's awkward and who's not, and why. Identify which collaborators are awkward. You can read about awkwardness here:
Now go look at your function that needs a fake of that awkward collaborator. It needs that fake because the awkward call is surrounded by logic you need to test.
Most of those functions, the overwhelming majority of them, will be shaped like this
//... some lines of prolog code awkward.call(...)
// ... some lines of epilog code
What do I mean, prolog? Well, it's the kind of code that figures out whether we should be calling the awkward, or it's the kind of code that takes some input and cooks it a little to create the arguments for that awkward call.
What do I mean by epilog? It's the kind of code that takes the result of that awkward call and cooks and massages it, or makes decisions based on its return.
That shape: prolog - awkward - epilog, that shape is why you need to have a fake to test that function.
But, one naturally asks, what the hell am I on about, it's not like you don't need the prolog and the epilog. I can't just not prepare before the call or not cook after the call. Bah, humbug, you cry!
The fix is simple. Change that code to read:
function() {
a = prolog()
b = awkward.call(a)
return epilog(b)
}
Bam. Test every case of prolog(). Test every case of epilog(). Test every case of awkward.call().
*Don't* test function().
How often does this scam work? VERY VERY OFTEN. It does not always work. Some loops develop their results incrementally, so my one call to awkward depends on my previous call to awkward. There is no way to test that w/o a fake.
But in nearly every other case, you can gain complete satisfaction without a single fake being in play.
There are a couple of special cases of all this, and some pretty damned slick technique that can handle the cases not covered by this trick. That's for another day.
Listen: You are a beautiful and intelligent creature, and you can do this.
But you gotta want to.
Learn "composed method".
Learn "strategy".
Learn "replace supplier with supplies".
This will still leave you with that tiny number of cases where you gotta roll a fake.
Roll it by hand, don't use an auto-mocker.
It will make you faster and stronger and, yes, happier.
• • •
Missing some Tweet in this thread? You can try to
force a refresh
I have been mulling, stalling, hedging, thinking, strategizing, so on and so forth, on a new project I've had in mind, for at least six months.
I think I'm about to pull the trigger on it.
And I'm not even gonna tell you what it is.
Because all the mulling, stalling, hedging, etc etc et fucking cetera had almost nothing to do with the geekery.
I make content for a living, or, more correctly, I make content for a non-living. I have project after project, three of them alive currently, to serve as the base and motive for my content.
Killing time while I wait for my birthday drink(s). I am prowling around a large java code base, looking at code I regard as "good", and partly picking nits and partly re-envisioning it in Kotlin idiom.
It is fun, sometimes, to look at bad code from lousy designers. But I am enjoying looking at reasonably good code from a designer I have a lot of respect for. Feels like it's even more fun.
A f'rinstance nit: don't use inline if's to handle pre-configured optional steps in an algorithm. Use a Strategy constructed at configure-time.
I read in bars, or anyway, I used to read in bars, when bars were a place I could go to. I miss bars terribly, and I miss reading in bars, too.
I like bar culture. And, tho I am of course a junkie, I have spent many an hour in bars, dead sober, reading my book and drinking my Diet Coke.
I have a friend, Sandy, who was the bartender at a place that was once my local. And I went in two or three times a week. I'd be there for very long stretches, six or eight hours, even.
True story: Eighteen or so years ago, I had a gig rolling code at an engineering company. We were writing a windows app using Microsoft Foundation Classes to drive a TTY interface to a box of various radio hardware junk.
I was gigged in by a guy I'd taught a c;ass (in MFC) to, because he liked that I knew my shit, and he loved that I spoke openly about joy, right in the classroom. right in front of God and everybody.
G amd I got along great. We were both heavy smokers and committed drinkers and hardcore software geeks. We spent many an evening after work, just hanging out, talking about geekery, smoking cigarettes, and drinking like fools.
The Dreaming was the first album I heard from Bush. It is stunning. I mean, every take, it is stunning.
Bush is one of the greatest "I may in fact be hopelessly insane" singers of all time, but whackos are a dime-a-dozen, what's astonishing about her work is how she works to give you the *grounding* you need to hear the insanity.