Wednesday, February 24, 2021

Reduce the code to the minimum

Reduce the code to the minimum but not less. This fundamental  principle of mechanical engineering fits also extremely well to software engineering and software resilience. Remove all unneeded wrapper, boiler plate code, indirections. 

  1. Less code mean less bugs
  2. Less code keeps your software side effect free
  3. Less code means less hidden knowledge 
  4. Less code - less dependencies
  5. Less code means less code to read
But be careful. Be sure that your code is well-covered from tests. Every mature project came's into a phase where the software developer delete more lines than they are writing new.

Tuesday, February 23, 2021

Exception handling - resilience in small

On of the most discussed software development topics is the right exception handling. Exception handling is one of the basic building blocks of resilience and without any surprise the correct exception handling depends on your application.

But here some well working tips to keep exception handling easy:

  1. Find out how important is this code place. If you compare it with a car, is it the breaker or is it the seat heating.
  2. If your code is the "seat heating" category then:
    1. Catch the exception
    2. Log the exception as error.
    3. Maybe count the errors as metric and put the metric on a dashboard.
  3. If your code is in the "brake" category then
    1. Maybe catch and log the exception with the context e.g. the related method parameter
    2. Throw re-throw the exception and handle it on the presentation layer (front end)
  4. If you can't clearly decide between the categories "seat heating" and "brake"
    1. handle the exception like category "seat heating"
    2. create an alert on the metric
  5. If you have an fallback use the fallback and count the usage via log message or as metric