Archive

Author Archive

Motivation

January 18, 2013 Leave a comment

I’ve been doing a lot of soul searching lately. There have been a lot of changes recently. Some for the better and some for the worse. While watching the video below, I nearly jumped out of my seat a few times because of the deja vu moments.

The two presenters are highly entertaining to watch. Although the title may be a little sensational, I still think the video promotes important messages. I’m sure a lot of people recognize the topics they discuss, but it’s still good to hear someone else talk about it openly. There are numerous topics in this video that resonate with me.

This is a 10 minute video about what motivates people. It’s an interesting video to watch, but I would take it with a grain of salt. There’s actually an entire book about this. The examples they use may or may not correlate to what happens in an actual work environment. While it may work for a subset of people, this certainly isn’t something that would work for everyone. However, I do agree with the three factors they discuss that lead to better performance and personal satisfaction:

  • Autonomy
  • Mastery
  • Purpose

This last video is John Carmack’s keynote at QuakeCon 2011. John Carmack is a brilliant programmer and is an inspiration to me. Just listening to him talk motivates me to go try and build something great.

Managers

January 16, 2013 1 comment

I was speaking with my manager recently and the conversation derailed a bit. Somehow we ended up discussing what I consider a good manager. In the past five years, I’ve reported to seven different people, each possessing their own unique traits that I respect. There are articles all over the web that lists the ideal traits of a manager. Just to list a few:

  • Empower your team and don’t micromanage.
  • Communicate well and listen to your team.
  • Encourage professional development.
  • etc…

However, I consider two things of utmost importance above all else:

If a manager promises my team something, then backtracks without discussing it with us, I will forever look at that manager differently. There is nothing that will demotivate me faster than working for someone I can’t trust.

To quote the fair process page:

  • Engagement. Involve individuals in the decisions that involve them. Get their input, allow them to actively PeerReview the ideas on the table. Respect individuals for their ideas.
  • Explanation. Everyone involved and affected must understand the reason why the decisions were made. Demonstrating the rationale behind decisions shows people that you have considered their opinions thoughtfully and impartially. Not only will this make people trust the decision maker but it will help them learn.
  • Expectation clarity. Once a decision is made, clearly specify the expectations for the people involved, what responsibilities they have. Even if the expectations are demanding, people want to know by what standards they will be judged and what penalties there will be for failure. Understanding what to do reduces useless political maneuvering and it allows people to focus on the task at hand.

Fair process goes hand in hand with trust. If decisions are being made without input from my team, I feel completely disengaged with the task in hand. If my manager cannot trust me enough to value my input, why should I go above and beyond for them?

For the managers I’ve worked with that employed fair process, it was an absolute pleasure working with them. I was committed and motivated to get the task done because I felt like I had a stake in the result.

A lot of the traits that I value can be found in the book Peopleware. Just like how the agile manifesto states, software development is more than just processes. If you value processes over people, you’re probably a bad manager.

User stories, features, and epics

January 10, 2013 1 comment

There have been a lot of discussions in my team recently about the definitions of a user story, feature, and epic. I’m by no means an agile expert, so this is just my opinion and interpretation. I’m the type of person who trusts their intuition, so the way we’re currently forced to group our requirements feels extremely awkward to me.

Currently every user story that is created must be grouped under a feature. All features must be grouped under an epic. By the way I’ve described things so far, it appears there is a hierarchical structure that must always exist: Epic -> Feature -> User story.

To be honest, I hate this. I don’t like it at all. If a user story is small enough to implement on its own, why do I need to bother creating a feature or epic? This screams process over pragmatism. If we’re forced to always create features and epics, they are no longer features that describe how a system works. Instead, we’re using them as categories or buckets of work.

After reading multiple articles around the web, I found this article by Mike Cohn that contains a very simple and concise definition for each.

To me, a user story is a requirement that can stand on its own. It doesn’t need to be grouped under a feature or epic. If a user story is too large but not large enough to be considered an epic, it may be broken down into “tasks” that will eventually be absorbed back into the user story after completion. Many people have the opinion that a user story should be sliced into multiple smaller stories instead of tasks. I disagree because that story will be sliced to the point where it doesn’t provide any business value on its own. Instead, they become system or technical stories. A user story should be something that delivers business value on its own.

If a user story may be broken down into multiple smaller stories that can provide business value on its own, then it may be considered an epic. I really like the way Mike Cohn described themes, or what we would consider features. They are simply a “rubber band” around a collection related of user stories. There isn’t a hierarchy between a feature and epic. Since a feature is simply a collection of related stories, there are times when a feature may be larger than an epic or vice versa.

Neither epics nor features are required. If a requirement is small enough to fit inside a single user story, then that is all there needs to be.

Again, I’m not an agile expert, so this is just my opinion and interpretation.

Team discipline over forced processes

January 8, 2013 1 comment

I always strive for my team to be as autonomous as possible. The best way for a team to perform well is to have the responsibility to decide how they work. The process should work for the team, not the other way around.

It really irritates me when I see agile zealots blindly following their step-by-step checklist. For example, some people have forgotten who our customers are. As a developer, my customer is the business. A typical agile zealot will value processes over business value. If it goes against their prescribed set of agile processes, the business must be wrong and we have set them straight right? Absolutely ridiculous.

“But that’s not Scrum”. Well guess what? I don’t care because no process is perfect. The process is not more important than the customer’s satisfaction. These agile zealots always claim to care about people and results more than processes, but they will interject if you don’t follow their checklist to the letter.

Great teams should always have the power to decide how they work, because ultimately they will be responsible for the outcome. Mistakes will be made, but it’s part of the learning process. At the same time, I’m not saying that once a process has been decided upon that it needs to be written in stone. A disciplined team will fine tune their workflow as the project progresses.

Advanced distributed systems design

November 11, 2012 Leave a comment

I just got home after spending a week in Miami attending Udi Dahan’s “Advanced distributed systems design” course. This was by far the best training course I have ever attended. In fact, I believe it was one of the best investments I’ve ever made for my career. I’m sure it will take me many weeks of reviewing my notes to fully digest all the information that was presented. I am extremely excited to start thinking about and using some of the techniques and concepts that I learned during this course. There is no doubt that it will take me several years of being a practitioner for these concepts and principles to become second nature, but the end result will be worth it.

If you are interested in distributed systems, I highly recommend attending this course if you ever get the opportunity.

Pluralize words

October 21, 2012 Leave a comment

Whenever I’ve needed the plural form of a word, I’ve always relied on the Inflector class from the Castle ActiveRecord project.

string plural = Inflector.Pluralize("planet");
Console.WriteLine (plural);

Since .NET 4.0, Microsoft has added their own PluralizationService class to pluralize words. Microsoft’s PluralizationService class is actually used in the Entity Framework tools to generate singular or plural entity names.

var service = PluralizationService
	.CreateService(CultureInfo.GetCultureInfo("en-us"));

string plural = service.Pluralize("planet");
Console.WriteLine(plural);

There are cases when both classes do not generate the same plural form of a word. For example, attempting to pluralize the word “virus” generates different results. Inflector will return “viri” while the PluralizationService will return “virus”. Neither generated the more common “viruses”.

Castle DictionaryAdapter – Using TypeConverter to map different types

October 20, 2012 1 comment

I’ve posted about the DictionaryAdapter a few times in the past (here and here). There are scenarios when we want to map more than just simple types to strings. For example, we have an interface IPerson with the property Birthday representing the date in ticks.

public interface IPerson
{
    string Name { get; set; }
    int Age { get; set; }
    long Birthday { get; set; }
}

If we attempt to map a DateTime to the property Birthday, an InvalidCastException will be thrown when we access the Birthday property.

var dictionary = new Dictionary<string, object>
{ 
    { "Name", "John Doe" },
    { "Age", 30 },
    { "Birthday", DateTime.Now },
};

IPerson person = new DictionaryAdapterFactory()
	.GetAdapter<IPerson>(dictionary);

Console.WriteLine(person.Birthday);

Fortunately, the DictionaryAdapter allows us to use attributes to define how properties should be mapped by creating a class that inherits from System.ComponentModel.TypeConverter.

public class DateTimeToTicks : TypeConverter
{
	public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
	{
		if (sourceType == typeof(DateTime))
			return true;
		
		return base.CanConvertFrom(context, sourceType);
	}

	public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
	{
		return ((DateTime)value).Ticks;
	}
}

We can decorate the Birthday property with the TypeConverter attribute and specify that we want to use our new type converter.

[TypeConverter(typeof(DateTimeToTicks))]
long Birthday { get; set; }

The previous example is a bit contrived. However, I have run into issues when trying to use the DictionaryAdapter with a result set from a database that contains NULLs. Here we’ve updated the IPerson interface with a Nullable<int>.

public interface  IPerson
{
    string Name { get; set; }
    int? Age { get; set; }
}

The following code will throw an InvalidCastException on line 17 after mapping the results from a SQL query:

using (var conn = new SqlConnection(connStr))
using (var cmd = new SqlCommand("select 'John Doe' as [Name], NULL as [Age]", conn))
{
    conn.Open();

    using (SqlDataReader dr = cmd.ExecuteReader())
    {
        while (dr.Read())
        {
            var dictionary = Enumerable
                .Range(0, dr.FieldCount)
                .ToDictionary(dr.GetName, dr.GetValue);

            IPerson person = new DictionaryAdapterFactory()
                .GetAdapter<IPerson>(dictionary);

            Console.WriteLine(person.Age);
        }
    }
}    

We can create another TypeConverter to check for DBNull and returns null if found.

public class DBNullable : TypeConverter
{
    public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
    {
        if (sourceType == DBNull.Value.GetType())
            return true;

        return base.CanConvertFrom(context, sourceType);
    }

    public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
    {
        if (DBNull.Value.Equals(value))
            return null;

        return base.ConvertFrom(context, culture, value);
    }
}

Again, we can decorate the Age property with our new type converter.

[TypeConverter(typeof(DBNullable))]
int? Age { get; set; }

Multiple threads and refreshing Spring.NET’s context

October 4, 2012 1 comment

One of our legacy applications uses Spring.NET as a service locator. In most cases, I generally agree that using a service locator is an anti-pattern. Unfortunately, this code is littered throughout the project:

var context = ContextRegistry.GetContext() as IConfigurableApplicationContext;
IService service = context.GetObject("name-of-object") as IService;

Spring.NET exposes a method that refreshes all the object definitions.

var context = ContextRegistry.GetContext() as IConfigurableApplicationContext;
context.Refresh();

Unfortunately, if another thread is attempting to resolve an object from the container while the context is being refreshed, a NullReferenceException is thrown.

System.NullReferenceException: Object reference not set to an instance of an object.
   at Spring.Context.Support.AbstractApplicationContext.GetObject(String name) in c:\_prj\spring-net\trunk\src\Spring\Spring.Core\Context\Support\AbstractApplicationContext.cs:line 1538
   at ConsoleDemo.Program.<Main>b__1() in C:\projects\ConsoleDemo\ConsoleDemo\Program.cs:line 30

A simple solution is to utilize the ReaderWriterLockSlim class to allow multiple threads to resolve objects while allowing us to block all the threads when we need to refresh the object definitions.

public static class ServiceLocator
{
    private static readonly ReaderWriterLockSlim locker;

    static ServiceLocator()
    {
        locker = new ReaderWriterLockSlim();
    }

    public static T GetObject<T>(string name) 
        where T : class
    {
        locker.EnterReadLock();
        try
        {
            var context = ContextRegistry.GetContext() as IConfigurableApplicationContext;
            return context.GetObject(name) as T;
        }
        finally
        {
            locker.ExitReadLock();
        }
    }

    public static void RefreshContext()
    {
        locker.EnterWriteLock();
        try
        {
            var context = ContextRegistry.GetContext() as IConfigurableApplicationContext;
            context.Refresh();
        }
        finally
        {
            locker.ExitWriteLock();
        }
    }
}

Developers and QA – pair testing

October 2, 2012 1 comment

I’m writing this from a developer’s perspective. I don’t have the experience or background to present this from a tester’s perspective.

Most people are familiar with pair programming and its benefit in a wide spectrum of scenarios. However, I don’t see very many people practicing pair testing. I find that pair testing with both a developer and tester to be extremely beneficial to both people. The savings in communication overhead is worth it by itself.

  • Collaboration – Not only do I rely on my testers to verify functionality, but to identify scenarios where a system or function would fail. In other words, testers are also users of a system. When soliciting feedback about a feature or update, I always involve the business, developers, and testers. Unfortunately, I rarely see this happening.
  • Knowledge sharing – Occasionally when I’m working with someone who isn’t as familiar with a system, they aren’t really sure what type of questions to ask. I find that people really open up once I start explaining the system from start to finish. Not all questions are going to be answered in a single pair testing session, especially for a complex system. Being able to ask questions face-to-face allows a person to understand the system faster and more thoroughly.
  • Mutual Learning – The best way to learn something is to teach it. Over many sessions, I’ve found many ways to test my own code more effectively and have gained new perspectives on how something may be used. Testers gain a more thorough understanding of the system they are testing and learns how a developer steps through and debugs issues.
  • Safety net – I find that one of the most valuable traits of a good tester is the ability to ask good questions. I very much dislike working with people who do not ask questions if they don’t understand a topic. There have been many times where asking questions have led me to question the way I’ve implemented something. Perhaps it was a small issue that I overlooked or a hidden issue that we managed to uncover as part of our collaboration. Whichever the case, it helps me from having tunnel vision.

In my opinion, breaking down the communication barrier between developers and testers is one the most important goals that a team can achieve.

Starting too many console applications

September 26, 2012 Leave a comment

We have a service that starts multiple instances of a console application using Process.Start(). During peak hours, there could potentially be 100 or more instances of the console application running. Obviously this isn’t an ideal solution, but it’s a legacy system that I’m currently supporting (if my boss is reading this, we need to redesign this system).

After a while, I noticed that many of the console applications weren’t starting and there were no indications of any problems until I looked at the event logs.

ConsoleApplication.exe - Application Error : The application was unable to start correctly (0xc0000142). Click OK to close the application. 

Searching online for the error 0xc0000142 didn’t yield much information. It seemed to be a generic error message that means either you’re out of memory or the application is corrupt. This problem took me a few weeks to diagnose. At first, I just shrugged it off as an isolated incident without looking for an exact reason. Unfortunately, this happened again recently which prompted me to look for the root cause.

The service that’s starting these console applications used to be load balanced over two servers. We recently moved this service onto just a single server since CPU and memory usage were fairly low. What I found out was that starting all these console applications resulted in desktop heap exhaustion.

This is a great article describing what the desktop heap is:

Every desktop object has a single desktop heap associated with it. The desktop heap stores certain user interface objects, such as windows, menus, and hooks. When an application requires a user interface object, functions within user32.dll are called to allocate those objects.

Part 2 of the article mentions that the non-interactive heap size for services is 512 KB. After some testing, I was able to confirm that the 0xc0000142 error started happening when we reached approximately ~120 console applications. The desktop heap monitor confirmed that heap utilization was high.

At this point, I would have to assume that we never exhausted the desktop heap when our services were load balanced across two servers. Since migrating to a single server, our desktop heap size was reduced by half.