Learning your tools
This time I’d like to talk about tools, the tools and frameworks we use every day.
I often relate to the Gardening metaphor when talking about software. A gardener knows his tools, he knows when to use a certain type of trowel not to damage the plant, he knows when using a bigger type of spade so that his work will be more efficent. Furthermore a professional gardener knows how to take advantage of a given technique, one that may not be relevant in theory, but in a specific context may be useful.
We are professional software engineers, we need to use the right tools, we even need to look into other tools in the market and then use a similar one that we have in our storage.
We tend to make one mistake though: we get trapped into our own habits.
Habits are good, habits are the realization that we have come to learn something that deeply that we don’t even think on doing that. The trap here is that we may follow certain habits when they are not applicable or even when there is a better pattern to apply in that context.
One Example is worth a Thousand words
Test cases in your testing framework:
Recently I was doing the FizzBuzz coding kata. In this kata we need to print a sequence of numbers but transforming some of them into “Fizz”, “Buzz” or “FizzBuzz”, given certain rules.
My tests were as follows:
I wanted to be explicit so that people could read my tests as documentation. While that is correct, imagine following this pattern in a larger and more complex solution. Tests become overcomplex, we need to maintain more lines of code.
In this scenario I have a single function that transforms the data: I send an input sequence and I get back an output sequence. It seems the perfect match to use TestCases.
I’m using XUnit test framework so that I did some research and found about InlineData, then I changed my tests like this:
Tests have become more concise and simple, yet they are explicit.
Creating tools, test cases in Mocha.
A trully proficient gardener may find that in a given context, none of the tools do a good job. What they do in that case is that they apply patterns that they know from other contexts, even creating new tools, to solve the new problem.
We, as proffesional software engineers, should learn more than one language. Even if you are a Ruby developer, by learning different languages, different paradigms, you will see other ways, you will find different solutions to similar problems. I ensure, you will come back to your regular environment to find out that you have become a more efficient profesional developer.
Imagine our friend the gardener using always the same shovel, no matter what the context is… Probably he won’t be hired that often.
We use Mocha as our testing framework so we did some research and found out that Mocha doesn’t support Test cases. It didn’t matter, we knew the language and we knew the concepts, so let’s try to implement test cases.
Learn your tools well to reduce work. Thanks for reading!