My function was doing too many things

Gemma Black
Gemma Black
Published in
2 min readDec 30, 2019

I was creating a semantic publishing tool to help with creating artefacts that can be deployed. I tried semantic release but I had a few problems and needed something that could work with CodeCommit. Here’s my entry function.

The problem with this, is that I’m using both dependency injection and optional internal modules. This increases the number of ways this function can work. Thankfully, by using test coverage, this issue was quantitatively qualified.

Note the % Branch? It’s 62.07%.

The function is lower down in the file, hence the difference in line numbers, but those lines refer to the or statements.

When I rely solely on dependency injection, the number of branches decreases.

Furthermore, the single responsibility principle is in play here. The publish function now only runs our commands in a particular order. It does not choose alternative commands of which to run. Instead, I now just load the injector with the typed adhered functions I want. I can use a factory function to do that. It will make the test much more straightforward.

I can have different runners. Maybe I have a CodeCommit to S3 runner, or a GitHub to Dropbox. I have flexibility whilst making this one function simple.

--

--

Gemma Black
Gemma Black

Chocolate-, brownie-, coding-, peace-loving, city girl who loves both nature and tech.