Planning Meeting–What went wrong?

Today we discussed how to develop a new feature that is needed to improve some performance issues. The interesting part took place in the end of that meeting.

The project lead asked: “How long would it take to finish that feature. Would it be possible to get it running until Wednesday?”
The developer answered: “We’ll complete that feature today!”
I argued that a one day estimation would not be applicable for such a task, regarding testing, deployment and so on.
The project lead answered: “I know. When he is saying he needs one day to accomplish a task, he actually will have done it in three.”
Both nodding their heads.

So I tried to explain what my concerns with this conversations were.
I told them that it is not acceptable to don’t let others know what they are doing wrong. If I won’t ever say that his estimations are totally wrong, he’ll never challenge his estimations.
So I tried to convince them that they both handled the wrong way. The one for the overhasty estimation and the other for his ignorance for a mistake.
Frankly speaking, of their reactions I didn’t feel understand, but never mind, this situation will recur and I will try to indicate that again.

It is not about whether the one day estimation nor the three day estimation were wrong or right. It is all about communication.
Don’t commit to something you aren’t sure you can stick with and point out others mistakes (in a gently way).

Name your code

I stumbled upon a code snippet that is not easy to understand, until you know what it is doing.I remember my colleague explaining it to me a while ago, but it seems that I forgot what it is used for since the last time I looked at it.

CallMethod(value + "");

So this is all of the code. It looks like it is used for converting value object a string. You might think, why the hell he isn’t using the ToString method?

CallMethod(value.ToString())

You would be right in most cases, but the real purpose of this usage is to handle null values and convert to a string. Another way to write it, maybe a bit more understandable.

CallMethod(value == null ? string.Empty : value.ToString);

Another possible solution is to introduce an extension method, this will give you the advantage of naming your code. Another coder will know what your intention was, without asking for it.

public static string ToStringOrEmpty(this object value) {
    return value + string.Empty;
}

I created a repository on GitHub for my commonly used extension methods. Currently it is rather empty but trust me, there is a lot to extend. https://github.com/dwoni/Extensions

Try to fix it before you try to break it

“As a user I don’t want to fix problems that could be fixed by the program itself.” – might be a user story that should be applied to almost every software out there.

If you want your software to succeed, you should think about some tasks you could take off of your users responsibilities. I use LINQPad as a code scratchpad during my daily work. Sometimes I want to test a simple statement with the ‘C# Expression’ feature.

image

In this case, as a programmer, you are familiar with ending each statement with a semicolon. LINQPad does not allow that when using single expressions. Why should the software raise an exception in this case, when it is possible to easily remove the semicolon at the end of line.

Defensive coding is your friend

This post is a response to Ayende’s post http://ayende.com/blog/160898/defensive-coding-is-your-friend please read it before continuing.

It took me a while to understand what Ayende is trying to say with this post. First I thought he is faking his test results. The test is expecting that Fiddler is running on the test machine and he was trying to ignore it was not running. So why his test isn’t simply looking like this?

[Fact]
public void Should_get_independent_notification_subscriptions() {
    using (var store = NewRemoteDocumentStore(fiddler: false)) {
        /// Do whatever was intended to be done
    }
}

Then I looked up Fiddler and found that it is used for logging HTTP-Traffic. I realized what he was trying to explain. When executing this test locally on his machine (where Fiddler seems to be installed) he wants to be able to log traffic for development purposes but on the build server no one cares about that.

So Ayende’s solution is to check if fiddler is running and then to decide whether the test should use it or not.

What annoys me is the fact that you make your test system dependent, or at least give it the logic to behave different on different systems.

A possible solution that comes to my mind is to add another test class that provides the same tests, but uses Fiddler instead of the direct Url.

public class LocalDocumentStore : IDocumentStore {
    public LocalDocumentStore() { 
        //Using http://localhost:8079
    }
}

public class FiddlerDocumentStore : IDocumentStore {
    public FiddlerDocumentStore() {
        //Using http://localhost.fiddler:8079 here
    }
}

public abstract class SubscriptionTestBase<T> : IUseFixture<T> where T : IDocumentStore, new() {
    IDocumentStore store;

    [Fact]
    public void Should_get_independent_notification_subscriptions() {
        using (var session = store.OpenSession()) {
            session.Store(new TestDocument { Name = "Name" });
            session.SaveChanges();
        }
    }

    public void SetFixture(T data) {
        store = data;
    }
}

public class LocalSubscriptionTest : SubscriptionTestBase<LocalDocumentStore> { 

}

public class FiddlerSubscriptionTest : SubscriptionTestBase<FiddlerDocumentStore> { 

}

OK, it is a lot of work compared to Ayende’s solution but it is more understandable, in my humble opinion. The class LocalSubscriptionTest is used on build server for automated testing and the FiddlerSubscriptionTest is ignored except I explicitly start this test for debugging purposes.

The missing piece in that puzzle is, that it seems that xUnit.net does not support skipping of classes (like it would be possible in NUnit for example).

Shortcuts you shouldn’t need to know

A few days ago I learned a new shortcut of visual studio  Ctrl + Break.
You might wonder what this shortcut does, I didn’t need it for more than five years of professional programming, but suddenly it appeared in my list of useful shortcuts.

I was mentoring one of our starters, extending a WPF application, some of my colleagues are developing and I’m not actively participating during my daily work. When I was coding, like I’m used to be (building instead of saving), I got very fast very upset. I never ever really recognized the building process, except when there where errors popping up, but in this case it was so annoying it takes about a minute to build. With our really high end notebooks it takes a few seconds in most of our solutions, fast enough to not pay attention to it.
OK, so I’d have to change my habits (saving instead of building more often), but when it comes to starting the application with attached debugger it still takes me over a minute to continue my work.
So what should I do when I accidently start the application or I detect an error in the code I just edited? I could go for a break or play with something lying around at our desks. After a few days during another accidently start, my partner quickly hit some keys and I could correct my code almost without any delay.
I asked him which keys he hit and he told me that it’s Ctrl + Break. I didn’t even know that that command exists.*

So now you know my story, but what I’m trying to tell you? That solution we are working on has almost 50 active projects, no wonder that it takes ages to build. So please, If you start detecting your build process, start splitting your solution before it is too late.

* Almost. I knew that shortcut from WinDbg already, but didn’t know that it exists in Visual Studio too.

Making your code a better place