New Simulators Library

I just published an early relese of my Simulated.FileSystem library. This library makes it easier to separate platform concerns out of my models. It works really well with a hexagonal architecture.

This library will define a set of ports for common external dependencies, with multiple adapters for each port. The initial release just includes a file system port, with two adapters: native file system and in-memory file system. Continue reading “New Simulators Library”

Emotions vs. Logic. Round 1. Fight!

I was calmly reading stuff when someone said something wrong on the internet. I got angry. It touched a common nerve so I got angry out of all proportion. I decided to respond to my anger…by saying stupid stuff on the internet that others can use to make themselves angry.

What made me angry? In the talk about values, the author said the following:

We humans are inherently complex and, while logical thinkers, we are also led by our emotions and some inherent animalistic traits that can’t reasonably be overcome.

Bullshit! I am not logical! How dare you denigrate me so! (as I said, angry.) Continue reading “Emotions vs. Logic. Round 1. Fight!”

Looking for bad code

I am giving a couple of workshops in the next few weeks on refactoring. It’ll be a guided fishbowl experience. I start the pair with code that has specific design problems, then I (and the audience) guide them in ways to refactor those problems away.

I’ve got some of my code to work with, but figured “hey! I should take some suggestions from the audience!” Continue reading “Looking for bad code”

Mock Free Example, Part 3: Fixing Untestable Code Sequences

In my character printer, at one point I had some code like this monstrosity. I know it’s a monster, because testing it

  • Requires at least one test double (the _character field).
  • Involves running a bunch of code not related to the unit test at hand.

Many people don’t think this code is so bad. They discuss various ways to test it, usually involving more mocks.

I’m going to show another way. Since it doesn’t require mocks and this is my blog, it’s a better way. Continue reading “Mock Free Example, Part 3: Fixing Untestable Code Sequences”

Simulating the File System

I recently posted an entry about replacing mocks with Simulators. That one used a Simulator from my running example code. Here’s another example, which may make the concept more clear.

This is a file system simulator. I’m building it out as a generic simulator, re-usable across projects. Right now, I’m using it Continue reading “Simulating the File System”

Mock Free Example, part 2: Simulators

One of the common uses for mocks is to replace expensive or stateful components, such as file systems, networks, GUIs, and databases.

However, I also see a cluster of other problems that arise at interfaces with these types of components, especially when they are system-level services:

  • Primitive obsession. Rarely are these APIs written as methods on an abstract object that return other abstractions. Instead, people pass around a lot of strings & things, which become arguments for static methods.
  • State. Partly because there isn’t a place to put it, state tracking becomes a mess. For example, you want to ask a web service for something. Are you logged in? Do you have to do something if you aren’t?
  • Lack of encapsulation. Those static methods end up everywhere. And often they end up with duplicate patterns everywhere (e.g., check for login before each call).
  • The API does not feel natural to the application. It doesn’t follow the project’s idioms, and doesn’t just flow into place.

For this reason, I use an entirely different sort of test double: a system simulator. And often these simulators stop being test doubles Continue reading “Mock Free Example, part 2: Simulators”

Testing Well-Written ASP.Net Pages

Llewellyn Falco recently posted on testing ASP.Net pages with Approval tests. His post talks about how to test the ugly pages out there: the ones that ignore all the MS guidance and just define everything in a big, ugly, page Load handler. I’m not sure what I’d recommend for testing well-written ASP.Net page view & templating. Perhaps something like the following? Continue reading “Testing Well-Written ASP.Net Pages”

Does Individual Accountability Imply Inability to Prioritize?

In conversation today, we hit on an interesting idea. It’s truthy; I’m not sure whether it’s true. In the experience of the people in the room, the following two statements were identical:

  1. Tasks, and responsibilities, are done by individuals. Individuals are accountable for outcomes.
  2. Every person in the company is assigned multiple parallel tasks, stopping at the point where each person has the number of tasks which makes them ineffectual.

The places where we have not seen #2 all do team-based task ownership, responsibility, and accountability. Is this true in your experience as well?

Continue reading “Does Individual Accountability Imply Inability to Prioritize?”