Tuesday, November 3, 2009
2 agile books and one IOException
Thursday, October 22, 2009
Sketchflow
I remembered that I've heard something about Sketchflow which is build into Expression Blend. Sketchflow is a rapid prototyping software which lets you design new UI-sketches very fast. So I surfed to Sketchflow overview and thought "well, I'll give it a try". So I downloaded Expression Blend 3 and a Starterkit with some neat videos. While installing, I watched the first one and was impressed what you can do with that piece of software: build your UI using predefined toolsets, add navigation to your sketched application and even gather feedback from various persons via a Sketchflow-player.
After 3 and a half hours of work, I sketched all paper-sketches into Sketchflow and showed it to Alex and Reinhard. Gosh, they were impressed. Here are two screenshots:
Monday, October 12, 2009
Pair Programming
We started at about 14:00 and wanted to add some unittests for a class Artem wrote. I already reviewed his code, so I knew it quite good. By the way, one result of the review was "where are the unittests?" - so I maneuvered myself in this position. Anyway, good quality-code needs some sacrifices *heroic*
I took the keyboard and Artem the mouse... No, just kidding. He was sitting beside me keeping an eye on my cursor. So we began with the first function and let Visual Studio build a test-stub and an accessor (yes, I love that!) for us. We discussed what to test for this method and I began to write code for it - easy. Not long afterwards, we found the first inconsistency which wasn't visible in the review and in the productive code either. Fixed it and continued. This went on and on, one unittest after the other. We discussed the relevant parts of the code and enhanced a few places.
But as time goes by, I noticed how unconcentrated I was and that I made more and more typos. What a luck that we almost had all unittests we longed for. So we created the rest and finished that session. It was 16:00 and I was exhausted like never before when writing some code.
I must say, that this was hard, but it was worth for it. You can't get such a tight feedback-loop when doing reviews and you can't produce code just by discussing it in a normal meeting. So, pair programming is great but exhausting!
Friday, September 4, 2009
CodeRush Xpress
I discovered that tool the day before I went on a 1-week-no-pc-holiday-trip. As I came back, I was eager to try it and it held all my demands.
I'm using

There's so much so discover for me. There's also a kind-of mod-community, because the API is open (DXCore) to extend. Great tool!
Wednesday, August 5, 2009
How to build a collection of Interfaces
Here’s the problem: we have some files and some devices which operate with signals. As a signal is one of our main objects, we want to return a collection of signals when opening a file or beginning a communication with a device:

But of course, we want to handle each signal the same, so a signal from an EDF-file should be from the same class as a signal from a device. We could define a signal-class in the Main-library like this:

But this constructs a circular reference. We could create a converter for each special signal and build a collection in the main-library of all signals:

Ouch – ugly. For every signal-type we need one converter. What happens when DeviceSignal changes? Hopefully, we update the corresponding DeviceSignalConverter... Here’s my solution:

We implement all interfaces a signal could be loaded / imported from in the main-signal-class and use generics to simulate a factory. A EDF-dll could have:
public interface ISignal {
int SamplesPerRecord { get; set; }
}
public class SignalReaderwhere T : ISignal, new() {
public override ICollectionGetSignals() {
Listsignals = new List ();
var signal = new T();
signal.SamplesPerRecord = 3;
signals.Add(signal);
return signals;
}
}
The signal in the main-library implements that interface:
public class Signal : ISignal {
public int SamplesPerRecord { get; set; }
}
We can now call the SignalReader and it returns us a collection of signals we can use:
public ICollectionGetSignals() {
SignalReaderreader = new SignalReader ();
return reader.GetSignals();
}
We can implement further signal-readers just by implementing the necessary interfaces into the main-signal-class. In fact, for each reader we created from Signal inherited classes implementing the interface the reader defines. With that construct, we can work without circular references and get a collection of objects we can work with.
Wednesday, July 8, 2009
Benefit for unit tests
From today on I’m absolutely convinced that unit tests are great.
The last three days I refactored my current project a lot – in fact I added 10 classes, deleted 6 and changed 25. If I would have done that in the past without unit tests, I a) wouldn’t have done that and b) if I really would have done that, it would have probably taken me 2 weeks to realize that my uncontrolled changes aren’t working and I wouldn’t get it to work in a reasonable amount of time.
But with my 250 unit tests, I checked every refactoring-step if my code still does what it has to do. And with that, I was absolutely sure about my changes. So, thank you, unit tests!
Monday, July 6, 2009
Clean Code
I just read the german edition of Clean Code from Robert C. Martin. The introduction made me love this book immediately by a simple drawing. There are two things I’ll take along from this book:
1) For each function f let f.LinesCount < 20
2) Comments are evil
These two rules need some clarifications of course. In fact, the demand to keep functions below 20 lines is a result of another rule: Don’t mess with abstraction-levels. If you see a function with more than 20 lines, this should be a good indication for a mix of different levels of abstraction.
The second rule points in the opposite direction of what I’ve learned at university: one tutor said to me that there should be more lines of comment than lines of code, so that another person could easily understand what you wanted to say. Today with C# and Java, this isn’t true anymore. The code itself became the comment. No more cyptic function-calls or Hungarian notation but intuitive named functions and variables telling what they’re doing.
Although I’m still feeling awkward without any function-header-comment, I slowly try to reduce unnecessary comments like this:
‘ iterate through all alarms
For Each a In m_colAlarms
And transform it into this
For Each alarm In _alarms
The difference is not big but the sum of all changes generates a nice picture.
So, the first dozen chapters are truly inspirational. After that, the book takes a look on bigger examples how to refactor whole classes. This is done step-by-step and after some steps, it’s getting boring. My advice: just read the first 12 chapters and start coding!
Wednesday, June 10, 2009
What a wonderful world
Recently I read a lot about the M-V-VM pattern and I wanted to try it out. So I started small with a WPF-application implementing a listview showing some events related to sleep medicine. I’ve created a simple model with a collection of various data. This model is the data-provider for a ViewModel which is databind to this view:

So far, so good; worked pretty easy. I then read something about the graphical ability of WPF, which should be very bad in displaying a lot of graphical objects. Again, I wrote a sleep-medical-application, but this time showing some random biosignals with events:

The problem here was the very long signal build of thousands of Polyline-segments. And indeed, this brought WPF to its knees. You can’t show some signals with the pure use of WPF-technology. I instead used GDI+ inside of a Canvas-element for the signal and the VirtualCanvas-technique for the events (read here about it). With that I managed to preserve databinding on the modifiable objects (the events): you can move them around and change their duration by dragging their border.
In a second step, I combined the model of the ListView with that of the biosignals and injected it into its ViewModel. Of course, every ViewModel is being unittested – what a wonderful world:
Thursday, June 4, 2009
C#-For and VB.NET-For
Yesterday I wondered why on earth my simple VB.NET-For-loop produced an error:
Dim collection As New List(Of Integer)
collection.Add(1)
collection.Add(2)
collection.Add(3)
collection.Add(4)
collection.Add(5)
For i As Integer = 0 To collection.Count - 1
Console.WriteLine(collection(i))
If collection(i) = 2 Then
collection.RemoveAt(i)
End If
Next
I’m coming from a Java / C#-background, so I tried the same loop in C#:
var collection = new List<int>();
collection.Add(1);
collection.Add(2);
collection.Add(3);
collection.Add(4);
collection.Add(5);
for (int i = 0; i < collection.Count; i++) {
Console.WriteLine(collection[i]);
if (collection[i] == 2) {
collection.RemoveAt(i);
}
}
Et voilá, the result is what I wanted. So I made my discovery of the day: C#-For isn’t VB.NET-For.
In the cold light of day and using the debugger, it seems obvious that the VB.NET-For doesn’t check the condition on every iteration. It just duplicates the loop as often as it is stated in the For-statement.
The C#-construct is smarter as it checks in every iteration if the condition is true. But if it’s true that this is the difference between the two Fors, then the C#-loop must be slower. So, let’s check it out:
Dim start = DateTime.Now
For i As Integer = 0 To 1000000000
' nothing
Next
Console.WriteLine(Now.Subtract(start).ToString())
Vs.
var start = DateTime.Now;
for (int i = 0; i < 1000000000; i++) {
// nothing
}
Console.WriteLine(DateTime.Now.Subtract(start).ToString());
And indeed, the VB.NET-For-loop wins on my system with 3.734s to 4.687s!
Sunday, May 17, 2009
Thread-Threat

Using lock = _interop.Lock
' do something with lock.ComInterop
End Using



