Software craftsmanship Tag

I can't count the number of times I found myself implementing some sort of cache. In many situations caching is really useful e.g. when the computation of a value is expensive or when loading of resources is involved. I bet you found yourself implementing a cache many times too. Probably you have also used a Java Map for storing the values. One disadvantage of using...

Read More

Working towards clean code is a priority for me when I develop software. For some time I've been using Google Guava for nearly all my projects. The reason is simple. Guava provides great facilities to beautify my code. Today I want to show you how I use Preconditions to avoid unnecessary if/throw statements and Optionals to improve my code semantics. [ Need expert advice for your...

Read More

With this effective Mockito Post I want to share a really simple pattern with you. We call this pattern "check answers" and we use it whenever we work with Mockito Answers. The code resulting from creating Mockito Answers generally looks ugly. But, as good programmers we care about test quality, right? :) Let's see how we can make better looking answers using the "check answer" pattern....

Read More

In the previous Effective Mockito post we saw how to use the @Mock Annotation to get a clean test. In this post I want to show you how to use Mockito's spy mechanism to eliminate testing troubles with third party libraries. Testing is one of the most important things in software development. I assume you agree with me because you decided to read this blog post...

Read More

As promised in the first part of the "Effective Mockito" blog series, I will concentrate on Mockito specifics in the followup posts. So, the main topic for Part 2 is Mockito's @Mock Annotation. When I write tests I try to follow an explicit pattern, called the build-operate-check pattern. This was described by Uncle Bob in his book "Clean Code" (Page 127, Chapter 9). The main idea...

Read More

A few weeks ago the news in Germany was that the average lifespan of German citizens has reached its highest level ever (Statistisches Bundesamt Deutschland).  This was good news but I was also surprised to hear that women still live longer than men. I can imagine a lot of contributing factors but maybe that's a long discussion better done over beers. One thing that I've observed,...

Read More

I have been pondering exceptions quite a lot lately. Especially how to break the bad news to the user. From a user's point of view there are three categories of errors: 1. User or domain errors These errors occur when the user enters invalid data, or tries to perform an action that the domain model does not allow. Typical examples of this kind of error are things...

Read More