January 2010 - Posts

Accounting for Cost of Sales with Currying

I have a quick question for you. If you’re selling a widget for $100 and the local sales tax is 8%, how much should you add to the cost of the item to cover the sales tax? If you said $8 or 8%, you’re losing money. To the tune of 64 cents a sale. (Do the math, 8% of 108 is $8.64.)

What’s 64 cents you ask? Over a hundred sales it’s $64, over a thousand it’s $640. And over a million sales it’s $640 thousand dollars! Granted, in the process of losing that 640 thousand dollars, you’ve made $108 Million in pre-tax revenue. But more than half a million dollars in lost profit is nothing to scoff at either. But that’s what every POS system out there does. I’ve just checked in the code for Azure POS (the Silverlight/.NET 4/Azure exemplar I’m developing for my Mix content submission) that does it right. The functionality gave me a good opportunity to demonstrate simulated currying in C#.

Indian Food, Lambdas, and Sales Tax

Currying is a feature of most purely functional languages (named after Haskell Curry) whereby a function that takes two parameters is transformed into two functions, the first function takes the first parameter and returns the second which takes the second parameter and returns the result. In fact most functional languages, multi-parameter functions are at their core represented just as that. To clarify let’s look at declaring a multi-parameter function in F#:

let applyTax(taxRate:double) (amount:double)
  //insert computation here and return result (declared as a double
  result;;

In C# this is equivalent to

public double applyTax(double taxRate, double amount)

Well not really. There’s a significant difference between the two and this is where currying comes in. The declaration in F#, when entered into the F# Interactive will give the following output:

val applyTax : double->double->double

This is read as “the value applyTax is a function that takes a double that returns a function that takes a double that returns a double.” So for instance if you know the tax rate (say .08) you can pass it to applyTax and have a handle to a function that will take the amount and apply an 8% tax to it. F# is pretty cool like that.

Getting Func<e> With It

So how can we do that in C#? Simply make an overload of ApplyTax that returns a func<double,double>

public func<double,double> ApplyTax(double taxRate)
{
    return (amount)=>{ApplyTax(taxrate,amount);}
}

Now I can create variables for the different tax rates at my various retail stores

var applyCookCountyTax = ApplyTax(.10);
var applyLakeCountyTax = ApplyTax(.08);

This is the plight of retailers in the Chicagoland area. There is a 10% sales tax in Cook county. That means you’re paying $20 more to buy a $1000 TV in Cook County than in Lake County and retailers close to the county line lose sales to this disparity. In reality you’d probably store the functions in a Dictionary rather than holding them in individual variables.

var taxAmount = store.TaxTable[“Cook”](100);
//taxAmount =8.70

The Secret Sauce

The solution to the question is simple algebra let x equal the amount of the sale and z be the tax rate you need to find y such that when x and y are added, multiplied by z and subtracted from their sum you get x.

x+y – z(x+y) = x
x+y – zx – zy = x
y-zy = zx

Given x and z solving for y is trivial. Now you can wear a smug smile when you make a purchase at Best Buy knowing that you’re not footing the bill for sales tax. That is until you realize that the REAL sales tax is the markup they add over their wholesale price for that TV you just bought.

Extra Credit

Wes Dyer has an interesting post about simulated currying in C# on his blog. Also I’d imagine that using dynamics it might be possible to declare a base class that auto curries any functions declared in

The Pomodoro Technique

I was going to talk about how my digital cleanse reminds me of a macro scale Pomodoro. Then I realized that I never really talked about the Pomodoro Technique. The Pomodoro Technique is a method for getting organized and being focused. It is a time management system created by Franesco Cirillo. I’m going to let him tell you how he came up with the concept:

One day in the classroom on campus where I used to study, I watched my classmates with a critical eye, and then looked even more critically at myself: how I got myself organized, how I interacted with others, how I studied. It was clear to me that the high number of distractions and interruptions and the low level of concentration and motivation were at the root of the confusion I was feeling.

So I made a bet with myself, as helpful as it was humiliating: “Can you study – really study - for 10 minutes?” I needed objective validation, a Time Tutor, and I found one in a kitchen timer shaped like a pomodoro (the Italian for tomato) – in other words, I found my “Pomodoro”.

So the basic concept is to take a block of time and devote it solely to a single task. Rather than saying “I’ll work on this task until it’s done” you say “I’m going to work on this task and ignore all distractions for X minutes. Then I will stop for a quick break. And work on it for another X minutes” The key to the Pomodoro is working within a box of time and then stopping to integrate what you’ve done up to that point. The break is just as important as the time box. Taking a break allows you to evaluate what you’ve done on the task up to this point. Cirillo recommends 25 minute time boxes with a 5 minute break.

Dealing with Interruptions

Invariably, when working on something, an interruption will occur. Someone will stop by your desk, your phone will ring, an IM will pop up, an email will arrive in your inbox, or your twitter client will chirp to alert you to a new tweet. Some of these can be avoided altogether turn off alerts for email and twitter; set your phone to DnD (send straight to voicemail or mute the ringer if you don’t have built in DnD); set your IM client not to disrupt you (use trillian to provide a nice auto-response saying you’re busy to help avoid offending someone who feels you’re ignoring them); and close your office door. Don’t have an office door you say. It’s still possible to address that issue. Just look at your timer and say “I’m busy right now can I get back to you in X minutes” and put your headphones back on that obviously didn’t provide a big enough hint that you didn’t want to be disturbed.

The standing rule is that if you can address the interruption within 15 seconds, you haven’t invalidated your Pomodoro.

That Five Minute Break

Remember that co-worker that tapped you on your shoulder 15 minutes ago? Follow up with him. Check your email, look at twitter, look up the name of that class that you needed to use for the matrix transform, take a five minute stroll around the office, get some water, go take a bathroom break. Do whatever it is you need to do just STOP WORKING ON WHAT YOU WERE DOING!

Multi-Pomodoro Tasks

No one is telling you to break down your tasks so that they all fit within a single Pomodoro. That’s as crazy as a soup sandwich. What the time box allows you to do is switch contexts if need be. Say the annoying co-worker (who sent an Email, IM, and Voice Message within the 25 minutes but still didn’t get the hint) alerts you that the client wants the header to be Teal instead of lime green and they need that update within the next hour (“make it 45 minutes since the hour started when I came to your desk”). You can reprioritize and use the next Pomodoro to make the lime green header teal.

The Activity Inventory

So how do you get these tasks? Just like lean and agile software development processes use a backlog for tasks that aren’t currently being performed, the Pomodoro technique uses an activity inventory. In addition because of the fine grained nature of Pomodoro there is a more localized activity inventory sheet: To Do Today. It’s just like it sounds, it contains the activities that you plan to do today. When a task arises (for instance that lime green header switch) add it to the appropriate activity inventory. For something that must be done today add it to the bottom of the to do today inventory. For something that can wait until another day put it in the general activity inventory.

A Lot More to It

Those are the basics, but there’s a lot more to the Pomodoro Technique. A key point to the technique is to eliminate interruptions. It gets easier with time. Practically everyone I’ve spoken to who uses the technique has marveled at how much more productive they have become. Just as important to the boxed time of focus is the break. The break allows you to “integrate” what you’ve done. Take a breather and note your progress. Think of it as a waking nap. As you advance the technique helps you go from recording how long tasks take in terms of Pomodori to estimating how many Pomodori a task will take. There are even practices to allow you to measure estimates against actuals and adjust your future estimates accordingly. In other words, it allows you to gauge you personal velocity.

Back to the Digital Cleanse

On a larger scale, my digital cleanse is like my break between Pomodori. It allows me to remove myself from my day to day and take a quick breath. I liked it so much that I will be starting each month with a DC. Looking at all I did with my last one, who knows what will happen this round.

Posted by Mike Brown | with no comments

Welcome to 2010

Yes I know I’ve already posted twice on here this year (more on that later). But this is my first post coming out of my Digital Cleanse. What did I do in that week away from twitter, facebook, and all the tech “news” sites like engadget, joystiq, etc.?

  1. Incorporated a company
  2. Finished the second book of the Icewind Dale Trilogy (I started reading that book 3 years ago and was only on the third chapter)
  3. Designed two inventions…one of which I will perform a patent search and if it’s clear file a patent
  4. Wrote high level visions of seven software products two of which I am combining into a single solution and developing
  5. Spent quality time with my girls every evening.
  6. Lost 12 pounds
  7. Got more organized
  8. Got my MVP Award renewed (this wasn’t the result of anything I did this week but rather over the course of last year)
  9. Reconnected with my network
  10. Celebrated my Grandmother in law’s 85th birthday.
  11. Posted twice to my blog in one week. (Three times if you count today).
  12. A few other things I’m not allowed to mention.

All in all it’s been an INCREDIBLE week. I’ve never felt so energized before. And there’s only more to come.

What I Learned

image

By forcing myself to forgo twitter and facebook and essentially “mindless” browsing, my mind had to fill the void somehow. It craved the stimulus that constant updates and bite sized nuggets of news used to provide. Fortunately, just before Christmas, I purchased a bunch of Piccadilly notebooks. I know Moleskines are all the rage, but I have a frugal mindset right now and these guys were heavily discounted at Barnes and Nobles. But I did see a really nice day planner Moleskine that caught my eye, I passed on it. One I selected to be my idea book (a soft covered ruled small notebook), another my journal and meeting note taking book (hard covered small graph paper), and a third is my design book (hard covered large graph paper). I feel naked without them. The first one that makes a Pomodoro notebook has a customer for life.

I bought some extras for my wife as well and showed her the pocket in the back where she can stuff all the receipts she likes to collect. She’s sticking with her other notebooks for the time being. But she does comment when she notices me opening my notebook “Uh-oh he’s pulling out the Piccadilly.”

I’ve decided that going forward, I will confine my usage of twitter to a set time each day. Facebook, it’ll be relegated to pure casual time. There’s not much there for me business wise. Most of my business socializing is through linkedin or Twitter. I’ve never really done the myspace or any of the other pure “social web” sites. Frankly, I don’t have the time.

Right now, I look at my time as an investment that is worth more than money. If I’m not doing something that gives me a return on that investment, I damn sure better enjoy it. Twitter in moderation is a good investment. Spending all day checking out your tweet stream isn’t (not that I really did that, but I spent more time than I care to mention with twitter open and having it closed for seven days made it patently obvious that there are better things that I can do with my time.

What did you do with your Digital Cleanse? If you didn’t do one, what are you waiting for?

Posted by Mike Brown | 3 comment(s)

The Duct Tape Programmer Revisited

Not too long ago, I responded to the reaction that many had to Joel Spolsky’s article “The Duct Tape Programmer”. My belief still remains that people missed the point due to the unfortunate titling (as well as the severe dating of the technologies mentioned). I think it might make the meaning of “duct tape programmer” more apparent to contrast the duct tape programmer with his antithesis: the bright shiny guy. And what better way to do that than with a case study: 3D Realms and Duke Nukem Forever.

Now for those who don’t know, Duke Nukem Forever was originally announced in 1997 as the follow up to wildly successful Duke Nukem 3D. How successful you ask? Duke Nukem 3D was self-published by 3D Realms and sold around 3.5 million copies. It doesn’t take a rocket scientist to realize that 3D Realms was sitting on a boatload of money. And therein lies the problem. Because 3D Realms was self financing development of Prey (which finally saw release a few years ago) and Duke Nukem Forever, they had full control over time and budget. 12 years later, 3D Realms threw in the towel and closed their doors.

The tragic thing is that Duke Nuke Forever had been “completed” five times over in those 12 years. Unfortunately just as they should have been marching toward development, George Broussard would see a new “must have” feature for Duke Forever demonstrated in a new engine. Instead of passing on that bright shiny object for this time and pushing on to release, he would have the team rebuild the game on the new engine. There are at least 4 documented instances of this occurring.

And that my friends is the difference between Joel’s Duct Tape Programmer and the Bright Shiny Guy. The duct tape programmer doesn’t give a damn about that new high resolution snowflake modeling, he wants to ship the product so he can start the next version using the high res snowflakes. That is why I wanted to be the Duct Tape Programmer. You go ahead and use products that are barely released on your enterprise critical system. I’ll use the tools that I’m familiar with. You can argue that the new stuff is sexy. What’s really sexy to me is shipping a product.

And in the end that’s what our job really is. Just ask the former developers at 3D Realms.

Posted by Mike Brown | 2 comment(s)

RIAlity TV

I am creating a video blog designed as a reality TV show called RIAlity TV. (Actually I'm designing it to be a Channel of RIAlity shows). The first show called "The Project Room:Catching the Wave" will document creating a software product from start to finish using the .NET 4 stack top to bottom.

Silverlight 4

MEF

WCF RIA Services

Entity Framework v2

Windows Azure

SQL Azure

The project will be a Point of Sale system (AzurePOS) designed based on the first example from Peter Coad's Object Modeling book. The goal is to have a V1 project ready to launch at Mix10. I've submitted a session to the open call for proposals. I'll recap the season and launch AzurePOS on stage. I’m looking for people interested in joining the fun. Right now I can use the help from people who can fill the following roles:

  • UI Designer: Take a concept and make it reality. Experience with Blend and Sketchflow is a plus. Integrator skills are a huge plus! We're going to put the Developer-Designer workflow through its paces. HTML/CSS/Javascript experience is good as well.
  • UI Developer/Integrator: Work with the designer to bring their vision into the application. Experience with Blend or a crazy XAML skills are a MUST. In addition experience with HTML/CSS/AJAX is helpful. The person in this role should be comfortable with the View Model pattern.
  • Backend Developer: A heads down C# coder who understands good Object Oriented Design. Knowledge of Entity Framework a plus. Experience with RIA Services a HUGE plus.
  • Web Developer: In addition to the main project, there will be some development needed for the RIAlity TV website. ASP.NET MVC 2 is the weapon of choice.
  • Web Content Manager: There’s a lot of content that needs to be edited for the site, experience with video editing is a plus.

If this sounds interesting to you, send me an email (mike.brown at azurecoding dot net) with a subject line “RIAlity TV”. There's a lot of information that I don't want to share publicly but at the very least this will be an opportunity to demonstrate your skills before an audience. I want to have the first episode in the can in time for voting (January 5-15). I’ll explain all privately.

Update:

The sessions are up on the mix site for voting, if you want to see it, add my session to your ballot.

Posted by Mike Brown | 1 comment(s)