Photo by Sebastian Herrmann on Unsplash

Fail Fast — a philosophy of life

Daniel Jankowski
Netcompany
Published in
3 min readJan 15, 2020

--

I like clean, simple code, short functions. When you look at them you can see what it is responsible for. Some programmers love a lot of nesting, conditions so that the code is complicated and hardly understood by the rest of the team.

Other thing is debugging. I don’t think about simple bugs, when you need a few minutes to solve ones. I usually was responsible for fixing bugs from category which we called “The X-Files”. We know that on some situation is a bug, and usually in one user in company (usually a person in a high position). I had to spend a lot of hours to identify what was wrong, usually when I understood everything, the fix took a short time.

The Fail Fast philosophy is easy to understand, but in some cases or by some programmers is considered unnecessary.

OK, it’s time for a few words about what Fail Fast is all about.

I wrote that it is easy to understand. If you know that a failure is possible, you should immediately stop the function.

I have prepared one structure example about connection to database. You can see there two interfaces: IConnection, IDataBase. Please focus on function Connect and its constructor — class Connection.

Program code:

Program result:

Connection completed — username: Chewbacca
Database connected

When password is empty, program doesn’t return any information of reason. We can check if it is connected, and we only see that it doesn’t.

If I will look at only for functionality, everything is good. User has to set username and password, system checks that input data is not empty, if not execute function “Connect” (write to console, and return true value).

Below is the body of function Connect:

Please look at line 8. Main function’s code is nested in two conditions. It is barely visible. In this case we can imagine, that username, and password is required. So if some of these values are empty, the system should return an exception. How it can be changed:

When we run the code, we will see what is wrong:

When you look at this code, you see the logic in the first lines of function, you can skip this and go to main code. This is very important, especially when you work in a team and the team is located in different countries, just like in Netcompany.

Please remember about it. When you are coding try to implement the code as simple as possible. Otherwise it will be hard to look again at it later and fix it. These good practices I base on my experience.

Why did I choose such a title — “Fail Fast — a philosophy of life” ?
You really should understand how important this is, and you need to think about logic, potential problems, and where it is possible to write the code as well as possible.

It will soon become your habit, and before you know it, you will start to apply this approach in life outside of programming.

You can follow/contact me through this link: Daniel Jankowski.

I would like to thank Birk Astrup for help.

This article is the property of Netcompany.

Netcompany provides IT solutions for both large enterprises and governments

--

--