Refactoring: Extract method

Extract method is one of the most popular refactoring method when dealing with legacy code. In legacy code we can often find methods that are very long. My favorite findings methods about 2000 lines of code. Cool, isn’t it? Those methods have usually many responsibilities and they are hard to debug. Having more than one responsibility in one method leads also to duplicated code because some responsibility is required in more than one place in code.

Read more

Using var keyword in C#

Keyword var is cool thing we can use to make our code more readable for other programmers and why not – reviewers. But var can also be used to make our code difficult to understand. In this case, lte’s say, we are overusing var. So, var is like wine – if one takes glass of it then everything is okay in the morning, but if somebody takes it couple of bottles then the morning will be awful. Or let’s say – too much var will kill you?

Read more

Interface for Processes

I had to write one data import/export utility that moved data from one database to another. Once I was finished the first round of coding I found one thing that needed refactoring – the import/export process wasn’t generalized. It was part of importer/exporter utility main class (it was console application). After some refactoring I got some common things to use in other tasks like this.

Read more

C# and Partial Classes

.Net 2.0 provided us with new feature called partial classes. Using partial classes we can use multiple files to keep the code of same class. Yes – we can put some methods to one file and the others to another file. Although partial classes may be extremely useful they can be also used to ruin system’s technical design if developers don’t know what happens behind the compiler.

Read more