Since the day I became a developer, I’ve always feared the Big What The Fuck.
The BWTF is not only related to the code you write, it is the lack of knowledge that threatens to crush your entire project. It can be as simple as a server misconfiguration that causes a gaping security flaw.
When the BWTF strike, there is nowhere to go; there is no place to hide. The BWTF is like the worst earthquake in the world: no building endures. A big part of your application, job and/or reputation goes to waste. And nobody wants this to happen.
How can you protect yourself from the Big What The Fuck?
Well, the first step is to accept that this risk exists. The next step is to conceive a strategy to mitigate that risk. After more than 10 years striving to avoid the BWTF I am now quite sure there is no way to remove that risk from your life. It is part of your life.
The best strategy to mitigate the risk of a Big What The Fuck is Testing.
I am not constraining the discussion to the source code. You should consider testing to be a strategy for a better life, with or without code. A strategy that you can use to fight the BWTF. Which is always lurking behind every corner, always present.
Say you plan to go holiday to the Red Sea, let’s try to work out a test to stress that decision:
- will I relax enough?
- will I cope with 6 days without my Mac?
- will it be safe?
- will I gain 4 pounds by eating all the time?
You do the same activity when coding a procedure that takes 2 integers and return the sum:
sum(1, 1)equal to
sum('a', 2)throw an exception?
sum('a', 2)exception a
The more tests that you are able to produce against a decision / procedure, the bigger
chance you have to find early issues, with less of a risk of a Big What The Fuck
in the future.
When it comes to a code scenario the most likely BWTF is to forget to consider a minor requirement from the customer. Then you deliver a product that will fail in the future when that minor requirement will manifest. Your phone will ring like crazy, your inbox will choke and you’ll move abroad to escape your shame.
The BWTF is due to the unpredictability of when the problem will arise.
The later it shows up, the less you’ll recall what the minor requirement was and where the problem lies within the code base. And how the hell it works! By the time an issue like that manifests itself, you may have moved to another technology.
In real life a Big What The Fuck can be even worse. Almost four years ago I bought a brand new house and I took a loan for it. Less than two years later I moved to Sweden to join a challenging job opportunity. To this date I still haven’t sold that house, but I’m still paying the mortgage. Of course this is not a life threatening issue, but I can assure you it is annoying to throw away money like that. What if I had prepared myself with a more accurate test when I decided to buy the house?
- are my career opportunities well developed close to the house?
- does my career ask me to be flexible about my location?
- will it be possible to sell the house without losing big money on it?
Well, I must confess that I didn’t create any of those tests at the time of the buying.
As you can see by yourself there is no known ways to completely remove the risk of a Big What The Fuck. The right way to behave is to mitigate that risk by running every decision / procedure against a good amount of tests. What the word good means in this context is up to you, but in general the more the tests the less the risk.
Another important point is that you can build you tests through time; it is always the right moment to add a new test. This is easier within a coding scenario. You may have missed a minor requirement but as soon you recognise it you can add a specific test to secure that requirement.
KarmaJS is a NodeJS command line tool which runs your unit tests. Among its features I should mention that you can run tests on multiple target browsers. You can test mobile devices connected to the same network. I use KarmaJS in combination with GruntJS or GulpJS to integrate tests into my building processes.
ChaiJS is an assertion library that works great with Mocha. It allows you to write
expect(foo).to.be.a.string so your assertions comes close to a natural language.
SinonJS is a mocking library which provides a set of tools to investigate your code. Does this method fire twice? Did it receive a string argument? You can go further and completely mimic an XHR request.
For a more sophisticated tool that brings a building process for single page applications
give a try to PoliteJS/Workspace.
DalekJS is a standalone alternative to WebDriver. Even if it is on an early stage it looks very promising.
So remember your Takeaway:
- the Big What The Fuck is always lurking and there is no way to avoid it
- testing is the best strategy you have to mitigate the risk of a BWTF
- you can apply testing to your professional and private life