Thursday, September 25, 2008

Anonymous functions rock!

I've been working on a project in C# 3.0 lately and I have to say that I am absolutely loving anonymous functions. I've found them most helpful working on my multithreaded code and I love them for two reasons.

First, it lets me keep related code even closer together. The code I'm doing has a lot of set up to do a task, then run the task in the background work and by using an anonymous function right inline with the setup / start the thread code, it's easy to see an overall picture of exactly what's happening.

My code went from looking like this (note all the whitespace between actual executing code):
void doSomething()
{
  // setup code
  ThreadPool.QueueUserWorkItem(doExpensiveOperation, null);
}

void doExpensiveOperation(object state)
{
  // Do the actual work
}


To this:
void doSomething()
{
// setup code
  ThreadPool.QueueUserWorkItem(delegate(object state)
    {
      // Do the actual work
    }, null);
}


As if making my code smaller and easier to see wasn't enough, using anonymous functions in this way also gets me closures. The great thing about closures is that it means you don't have to pass a whole lot of data to your function that actually does the work. The easiest thing is for me to show you an example...

In the past where I would have had to do this:

private class ExpensiveOperationData
{
  public Foo fooObj;
  public Bar barObj;
}

void doSomething(Foo fooObj, Bar barObj)
{
  ExpensiveOperationData data = new ExpensiveOperationData();
  data.fooObj = fooObj;
  data.barObj = barObj;

  ThreadPool.QueueUserWorkItem(doExpensiveOperation, data);
}

void doExpensiveOperation(object state)
{
  ExpensiveOperationData data = (ExpensiveOperationData)state;
  // Do the operation using data.fooObj and data.barObj;
}


Now I can do this:

void doSomething(Foo fooObj, Bar barObj)
{
  ThreadPool.QueueUserWorkItem(delegate(object junk)
  {
    // Do the operation using fooObj and barObj;
  }, data);
}


I can't get over how nice it is to get rid of all those extra hoops I used to jump through just to get the data I wanted to work on into the thread.

Friday, August 15, 2008

Don't handicap my objects!

I've been doing some reading today and I keep running into a theme, that bothers me. I keep running into this idea that the functionality of individual classes should be limited so that if, for example, the database is changed, its effect is limited.

On the surface, this seems like great advice, and I honestly think that the intent correct. The problem I have is that the authors I've been reading have either not been going deep enough into their proposed solution, or they're missing an obvious solution that would make everyone's lives easier. Instead, it seems that they want to trade away the logical grouping of functionality within objects to avoid ripple effects when making changes. Ripple effects are bad and we need to avoid them for code to be maintainable, I just don't think we need to make that trade in this situation.

In this situation, you can have your cake and eat it too. So you don't want your TinyWidget class to have code to look up its price in the database that has to change when you go international and now you need to look up the price in dollars for Americans and pounds for Brits. That's great! But instead of taking the GetPrice function away from TinyWidget and putting it in the DatabaseAccess class, why can't TinyWidget.GetPrice just be a thin wrapper over DatabaseAccess.GetPrice?

Don't handicap my objects in the name of flexibility, create flexibility by encapsulating functionality in low-level objects and using thin wrappers in the higher-level objects.

Tuesday, August 5, 2008

Introduction

I know I'm doing this in kinda the wrong order, but that first post is what finally pushed me over the edge to start a blog. For the 0.00001 of you who don't know me, my name is Jon Norton, and I work as a civil service engineer for the Navy. At home, I have the best family a guy could have, my wife, Kathleen, 6 month old son, Josiah (we have a baby blog at nortonbaby.blogspot.com), and our cat Ande.

My intention with this blog is to try to post something at least once a week that has something to do with software. From time to time, I might also post something about cycling or music (my primary hobbies) or even just some new theory of life, but I plan for this to be mostly technical. If I happen across more thoughts and the time to write them down, then who knows, but for now my promise to you is one a week.

Look at that, I've already doubled my target for this week!

NSPS vs. GS

I was reading this article by Mary Poppendieck on compensation of agile software development teams. As I read, I started comparing her “dysfunctions” and “guidelines” to the compensation system I live under now (GS) and the one I’ll be living under in the near future (NSPS). By the time I got to the end, I realized that it might be useful to actually write down some of my observations as a way to better understand my own thoughts and to share with others.

DYSFUNCTION #1: Competition

“…ranking people for merit raises pits individual employees against each other and strongly discourages collaboration…”

NSPS – Can anyone say pay pools? Under NSPS, the better the guy who sits next to me does, the less money I make. Hopefully the pay pools will be biggest enough that my performance has no impact on my coworker’s pay, but I doubt that will be the case. The system relies on the ability of the pay pool committee to be able to rank people which to me implies some level of knowing who we are. This means it can’t get so big that you can guarantee some sort of equal distribution of performance which is what you need for the pay to be truly fair and performance based. Thumbs down.

GS – There’s no real incentive to compete in the GS system that I can see. In general, my pay is based on what I do, and not a comparison of me to those I work with. Thumbs up.

DYSFUNCTION #2: The Perception of Unfairness

“There is no greater de-motivator than a reward system that is perceived to be unfair. It doesn’t matter if the system is fair or not. If there is a perception of unfairness, then those who think that they have been treated unfairly will rapidly lose their motivation.”

NSPS – Like all government compensation systems, NSPS is designed to be fair beyond our wildest imaginations. I’ll rate this one as a thumbs up for good intent, but I am concerned that the system is so complex (see our weeks worth of training on how to “navigate” it) that rather than being fair, it will reward those who know best how to work the system. Thumbs up. (I guess)

GS – I guess it depends on how you define fair. Do we all know what we need to do to get raises and are the standards the same? Yes. Could I make twice what you do despite the fact that you’re twice as productive simply because I’ve been around 20 years longer? Yes. I guess I’ll give the GS system a thumbs up on fairness, but I don’t have to like it. Thumbs up.

DYSFUNCTION #3: The Perception of Impossibility

“…the more likely case is that the promise of a bonus that was impossible to achieve would make the team cynical, and the team would be even less motivated to meet the deadline than before the incentive was offered.”

NSPS – In some sense I think my NSPS training has tried to convince me that it will be impossible to get a 5 (the highest possible rating), but on the other hand 4 and certainly 3 seem attainable. By stressing how rare and exceptional 5s should be have they managed to dissuade us from trying to get there? Or by dangling the 3-4 carrots in front of our faces are we still motivated? I think I’m going to have to go with the former. At this point, I’m pretty sure that I could move Mount Everest and still only get a 4, so why does 5 exist? I think they’re just teasing me. Thumbs down.

GS – I’m pretty sure that under the GS system, whether or not I’ll be rewarded depends entirely on who is my boss and how much I campaign for the bonus / promotion / pay increase. I guess that doesn’t seem impossible, but I almost want to say that the demotivation is just as bad as if it did. On the other hand, I think this dysfunction is about unreachable carrots and I really don’t see any of those. Thumbs up.

DYSFUNCTION #4: Sub-Optimization

“I recently heard of a business owner who offered testers five dollars for every defect they could find in a product about to go into beta release. She thought this would encourage the testers to work harder, but the result was quite different. The good working relationship between developers and testers deteriorated as testers lost their incentive to help developers quickly find and fix defects before they propagated into multiple problems. After all, the more problems the testers found, the more money they made.”

NSPS – I can’t think of anything that does this. Thumbs up.

GS – Ditto. Thumbs up.

DYSFUNCTION #5: Destroying Intrinsic Motivation

“…once employees get used to receiving financial rewards for meeting goals, they begin to work for the rewards, not the intrinsic motivation that comes from doing a good job and helping their company be successful.”

NSPS – I can definitely see this happening in NSPS. The way you get a raise is to make a goal at the beginning of the year which you meet and / or exceed by the end. This will almost certainly motivate us to work hard on the things that are our official goals and not on those that have no bearing on our end of the year review regardless of their relative importance. Thumbs down.

GS – I’ve seen myself and others be rewarded time and time again for simply finishing a project, sometimes years behind schedule. The first time it made me feel pretty good and like my efforts were noticed. However, as I began to expect these awards, the positive effects quickly subsided and were completely overwhelmed by my bitterness when I was not rewarded, or worse, the people I worked with were but I was overlooked. In the interest of fairness, I believe this system will remain in place and essentially unchanged under NSPS as well. Thumbs down.

GUIDELINE #1: Make Sure the Promotion System Is Unassailable

“Usually, job grades are embedded in titles, and promotions make the new job grade public through a new title. A person’s job grade is generally considered public information. If employees are fairly placed in their job grades and promoted only when they are clearly performing at a new job grade, then salary differences based on job grade are generally perceived to be fair. Thus, a team can have both senior and junior people, generalists and highly skilled specialists, all making different amounts of money.”

NSPS – Because the government makes promoting people so difficult, one of the main goals (as far as I can tell) of NSPS is to remove all of the grades by creating pay bands that cross what would be multiple GS grades. Thumbs down to NSPS here.

GS – GS has plenty of grades, but good luck cutting all the red tape to get that promotion. From my experience, and the opinions I’ve heard, the best way to get a promotion is to find work in an organization that’s good at working the system. Thumbs down.

GUIDELINE #2: Deemphasize the Merit Pay System

“When it comes to the evaluation system that drives merit pay, it’s best not to try too hard to sort people out.”

NSPS – As best I can tell, NSPS is all about ranking and stacking employees to determine their pay. To make matters worse, you’ll likely be ranked against the people you work most closely with leading to a situation where being average among superstars will result in worse pay than being exceptional among losers. Thumbs down.

GS – You either pass or fail your evaluation and whatever salary increase you get is based on years of service so not too bad there. On the other hand, merit pay in the form of bonuses (on the spot (six months later :-)) awards) is most certainly used. My personal experience has been that, as Mary predicts, I’ve been more frustrated and demotivated by not receiving these bonuses than I have been motivated to work harder when I receive them. Similarly, when the “top individual/team of the year” award goes to the cleaning crew, the rest of us highly skilled and technical workers get a little bitter that our performance is not being rewarded. Seriously, new cleaning crew was much better, but are we really saying that having cleaner offices was more important than any of the accomplishments the other teams and individuals had? You can also receive a salary increase as merit pay, but as best I can tell these are relatively rare and generally well deserved so I don’t think these are a problem. Thumbs down.

GUIDELINE #3: Tie Profit Sharing to Economic Drivers

“Nucor Steel started with the realization that profit per ton of finished steel was its key economic driver, and based its profit-sharing plan on the contribution a team makes to improve this number. So, for example, a team that successfully develops a new steel-making process or starts up a new plant on schedule will not see an increase in pay until the process or plant has improved the company’s profit per ton of steel. Thus, Nucor avoids sub-optimization by tying its differential pay system as closely to the economic driver of its business as possible.”

NSPS – Compensation in NSPS is based on how well I do at achieving the goals I set at the beginning of the year. These goals are supposed to have a direct tie to helping your organization perform its mission. Therefore, assuming that NSPS works as advertised my compensation is tied to the extent to which I help my organization. Thumbs up.

GS – Compensation is based on your organization’s mission only in the broadest sense. Unless you’re in management, it’s unlikely that you really need to think much about mission. Thumbs down.

GUIDELINE #4: Reward Based on Span of Influence, Not Span of Control

“Conventional wisdom says that people should be evaluated based on results that are under their control. However, evaluating individual results, rather than group results, creates competition rather than collaboration among the team members.”

NSPS – It’s all about the individual in NSPS. I suppose one of my goals could be to complete a team project, but my gut says that would be considered a bad goal because it’s hard to know that it will be achievable. The only way I can see a team getting compensation across the board is in the form of on the spot awards, the breadth of which is entirely up to the person writing up the recommendation. Thumbs down.

GS – The only way I can see a team getting compensation across the board is in the form of on the spot awards the breadth of which is entirely up to the person writing up the recommendation. Thumbs down.

GUIDELINE #5: Find Better Motivators than Money

“Once you go down the path of monetary rewards, you may never be able to go back, even when they cease to be effective, as they inevitably will. Make sure that people are fairly and adequately compensated, and then move on to more effective ways to improve performance.”

NSPS – As far as I know, there’s no attempt in NSPS to find any non-monetary motivator. Thumbs down.

GS – Ditto. Thumbs down.

I guess if this were simply a mathematical contest, GS wins 4 – 3 over NSPS. However, I’m more concerned that the “winning” score was only 4 out of 10. Working for the government has a lot to offer in terms of benefits and stability, but is that all it has to offer? I’m fortunate enough to work with a team that makes me enjoy most of my days at work but if I didn’t things wouldn’t look so good.

When it comes down to it, I wonder if the real problem isn’t the shear size of the government. The longer I work, the more I believe that to truly be compensated “fairly” the only hope we have is if our direct supervisor determines our salary, but there’s no way that something like that scales to the size of the government. When your “business” is the US government, the only way you can hope to be fair across the board is to create lots and lots of rules which inevitably result in some people being paid much less than they’re “worth” and some being paid much more than they’re “worth”. But hey, it looks fair (so nobody gets sued) and it keeps all the people in the middle safe.