TDD

Refactoring Strategy: Move It Where You Can Test It

When I can’t test it where it is, I look to move it somewhere else, where I can test it. Today’s notion isn’t so much a single refactoring as it is a strategy that can be achieved in different ways (and different multiple steps). A modern and frequently occurring case: using a cool framework to expose service endpoints, we write a function and then we annotate it and poof, it’s an endpoint. This is how Java+Swing works, or Python+Flask. When …

Refactoring Strategy: Move It Where You Can Test It Go to Post »

Refactoring: Invert Dependency With Observer

Another refactoring today: Use the observer pattern to invert an infelicitous dependency. In and of itself, this is a modest refactoring, but its smell often co-presents with others, and unraveling it all can be tricky. (Note: We aren’t remotely done talking about first and second-order refactorings, there are plenty more to go. But I’m not writing a catalog, I’m working a project, so when a hefty one like this comes along, that’s when I’m talking about it. You’re gettin’ em …

Refactoring: Invert Dependency With Observer Go to Post »

Refactoring: Demeter-Wrapping

Today, another small 2nd-order refactoring. I call it "wrap a Demeter". As with the others, this is a very modest step, but still quite useful in some situations. Demeter violations are places where a client accesses not just an upstream service, but that service’s upstream services, or even that service’s service’s upstream services. It’s a common problem in evolving code, and left untended, a classic source of unchangeable code. Demeter calls look this: a.getB().getC().doSomething() a is getting a B, but …

Refactoring: Demeter-Wrapping Go to Post »

Large-Scale Refactorings

Large-Scale Refactorings — given the recent refactoring-related muses, a respondent asked me to talk about large or larger scale refactoring work. (I love it when people’s questions trigger my writing. Please do ask these things.) First things first, “large scale refactoring” is really a colloquial expression, a shorthand we sometimes use, but in my experience there is no such thing, for two reasons. The first reason is definitional. Remember, refactoring doesn’t mean “changing my design”, it means “changing my design …

Large-Scale Refactorings Go to Post »

Second-Order Refactoring: Narrow The Question

Another small second-order refactoring for you today. I call it “narrow the question”. If you’re asking an object for data, ask for exactly what you want to know, instead of what you’d need to compute what you want to know. A very simple example: the PlayerView wants to disable/enable some of its controls when the Player is actively playing. In the “before” code, PlayerView asks the Player for its PlayerState and decides, based on its value, whether that means the …

Second-Order Refactoring: Narrow The Question Go to Post »

TDD on the Front End

A recurring respondents’ theme is “TDD is irrelevant in front-end code”. It’s easy to offer/receive this comment combatively, but I think a little more rich discussion of the factors involved might bring us to new and different positions about UI and TDD. Most folks who offer that are living in some sort of JS world: their code is client-side scripts attached to html pages to render various contents received from another application. Their browsers are in effect frameworks, inside of …

TDD on the Front End Go to Post »

Readability And Scannability

I distinguish quite strongly between “readability” and what I call “scannability”. I think that our trade’s pedagogues, even our very good ones, conflate the two, and in so doing inaccurately describe programming and ineffectively prescribe remedies. Maybe the way to approach the idea is through your experience of seeing. Humans — most vertebrates, in fact — rely heavily on “seeing”. The fabric of our experience is richly visual. A large portion of our neocortex is given over to it. Its …

Readability And Scannability Go to Post »

Kontentment And Human Arcs

Aight. I been away from programming for a couple of months, but there was a reason I started talking the other day about the kontentment project: I’m wanting mucho change in it. For a talk I’m giving, I want the ability to draw human arcs, with the same ease with which I can draw human lines. So I set out today to get that in. Human straight lines start with a line segment AB. Pick two random locations on that …

Kontentment And Human Arcs Go to Post »

The Cost of Changing Microtests

The “How I Work (Test-Driving Mix)” drew some questions and comment. How I Work (Test-Driving Mix) Here’s one: a respondent says, “If I write a lot of small tests and I change how a feature works, I have to change or throw out all those microtests, which is a lot of work.” (The respondent proposed an answer for this problem, and it’s not a bad one, but raises some other questions we might get to later.) The one-liner response: “For …

The Cost of Changing Microtests Go to Post »

How I Work – Preaching And Practicing

A respondent asks, "Are you always able to practice what you preach? I don’t mean intentionally dropping but unintentionally as your mind is sloppy. I have great difficulties in applying 100% of my "knowledge" 100% of the time." Sometimes questions open up huge areas with lots of issues and subtexts and angles, and this is one. It’s too big to fit in one or two tweets. First, the direct answer: Oh, hell no. I am definitely not always able to …

How I Work – Preaching And Practicing Go to Post »

Scroll to Top