Book review “Developer Testing”

Testing is a craft that requires not only effort of a test team. Also developers are obligated to take their share into testing. While wanting to increase the awareness of testing within our development team, I picked up the book “Developer Testing”, written by Alexander Tarlinder. As the title sais, it focuses on what a developer can do to increase the quality of his or her software by testing. In this post I will shortly describe the book and what you could benefit from it.

Read More…
Posted in Books at January 8th, 2020. No Comments.

Getting the most out of a code review

Code reviews are most of the time introduced within a team to have an additional pair of eyes. Developing is a human practice, hence can lead to mistakes. When you’re developing a piece of code, you can miss things like wrong assumptions regarding your design or code that might cause issues. Things that your peer might address.

If you as a developer put your work to review, it feels like that you have to go to a jury and people will judge your work. Although this could feel like this, it is also an opportunity for you to grow as a developer. Other people might have different insights and give you hints and tips to different solutions. It will also catch up issues and typo’s in upfront before delivering.

What does it take to have a productive and good code review? It first starts with good preparation; knowing what the code does and behave before actually starting to review it. Then we can wrap it up and give the reviewer some suggestions that he can look at, without being aggressive.

Let’s go through these steps and look them into detail with some suggestions how to tackle them.

Read More…
Posted in Best practices, Scrum at October 24th, 2019. No Comments.

Tasks and the AggregateException

When running a task asynchronous in an asynchronous environment, you can catch exceptions as you just using asynchronous code. When an exception occurs, C# will catch any exception and put it into the Task that will be returned to the caller. Furthermore, the Task becomes Faulted. The exception will be thrown now at the place where the await is put to wait for the result of the asynchronous call which caused the exception.

This changes however when calling a asynchronous task in a synchronous way.

Read More…
Posted in C# at August 13th, 2019. No Comments.

Passing exceptions between logical layers

Assume you have a layered system, build-up using the separation of concerns principle. We have a UI layer, a services layer and a database layer. The UI layer communicates with a service layer, which communicates with a database layer. As the names describe, the UI layer is responsible for showing an UI to the user, the services take care of main logic of the application and the data access layer communicates internally with a database.

Read More…
Posted in Best practices, C# at July 19th, 2019. No Comments.

Multiple return paths

Some argue that you shouldn’t have multiple return paths within our code. What are the benefits of having just one entry and one exit point?

Readability

You will keep the flow simple by having just one entry point and one exit point where the result is returned. In this case the code will be easy to read: you can simply read where the value is changed and where the end result is expected.

Controlling your object lifetime cycle

The main origin of the argue having only one return path, has its origin at languages like C or C++. In these languages you actually have to allocate memory when you want to use an instance of an object and deallocate it when you don’t need it anymore. If you forget the last one, you end up with memory leaks. Let’s say you create the instance and after that you return a value when some condition isn’t met. In this case, the line where your object is deallocated will not be called anymore.

A valid use: checking preconditions

A valid point where you could enter multiple return paths is at the beginning of a method, where you check the preconditions of your method. If a user of your method passes invalid arguments, you can quickly return a default value then have additional checks in your code.

 

Posted in Best practices, C#, C++ at June 12th, 2018. No Comments.

Tool for checking which process blocks a certain file

Not necessary within programming, but sometimes you encounter a situation where a file is blocked and you can’t think of which program is actually locking this file. I used to use LockHunter, but the main drawback of this tool is that you have to install it. If you have a situation where you don’t want to install a tool like this, you can use Handle which is part of the Microsoft SysInternals. You can find it over here: https://docs.microsoft.com/sysinternals/downloads/handle.

When you run it in a command prompt, you get an overview of all processes which are running on your computer and an overview of which files it is blocking at the moment.

Posted in Uncategorized at February 28th, 2018. No Comments.

Goal setting

Each year, people will make new year resolutions for the next year. How can you set goals that will succeed the next year?

Read More…

Posted in Personal growth at December 31st, 2017. No Comments.

The art of writing unit tests

With keeping up the quality of your code comes writing unit tests. In its origin, a unit test tests the behavior of a method of a certain class. People tent to fall into writing more integration of system tests, where they test several components at once. Unit tests then become very hard to maintain. What does a good unit test consist of and what do we test?

Read More…

Posted in Uncategorized at December 27th, 2017. No Comments.

Prevent subscribing to an event twice in c#

Events in C# use the observer pattern, where an observer can subscribe itself to event generated by a subject. Within C# the observer can subscribe itself multiple times to the subject. When the subject fires the event, the observer gets multiple events.

The best way to prevent is to be keen on the life-cycle of your events; subscribe at the right place at an event en un-subscribe from the event also at the right place. How can we have a defensive mechanism, that prevents us subscribing multiple times at an event?

Read More…

Posted in C# at December 20th, 2017. No Comments.

Using libraries in a clean way

The software we write, most of the times depend on third-party libraries. Take for example Log4Net or a device driver. The problem in many projects is that the third-library libraries are much interwoven with the production code.

Herein lies a number of problems:

  • What if you want to change the library you are using?
  • What if the structure the library uses does not meet your design?
  • How about unit-testing (think of the fact the library might use local resources like physical devices)?

Uncle Bob states in his clean architecture that within a good design, the whole application isn’t aware of these third-party libraries. Think of a plug-in like ReSharper. At Visual Studio they didn’t have to change anything in their code to support the ReSharper plugin. Only the plugin knows about the existent of the other part of the software.

How can we create such an isolation and separate our libraries from our main architecture?

Read More…

Posted in Design patterns, Unit testing at December 12th, 2017. No Comments.