Archive for December, 2009

The Next Decade in Software

The scientists are already hard at work at coming up with predictions for the next 10 years. I thought it would be interesting to extract from the list, the predictions that are directly related to software … along with a few recommendations on how to get started today.

  • Augmented Reality
    This one is almost already a reality. A number of iPhone apps use the compass, gps, and camera as a viewport to overlay information on top of the world. A few years ago, Johnny Lee posted some amazing videos on how to use cheap consumer hardware to meld real and virtual worlds. It is clear that 3D graphics programming will be very helpful in this field … why not start learning now?
  • True artificially intelligent computer programs
    This one seems to be the most far fetched. Not because the field is not progressing, because it is, but because it’s been promised for so long. The biggest problem I think is lack of a clear goal; you can say you want something that learns, but learns what? There needs to be a catalyst that makes it clear what people really want/need from an intelligence. In my opinion, the game industry is pushing the state of the art here.
  • Cell phone apps that will act as a health monitor … Sort of an OnStar system for the body
    Since the iPhone proved to everyone that you can have a powerful computer in your pocket, new devices have started appearing that try to piggyback off of the success. I’m looking forward to more people making symbiotic peripherals for phones like the iphone, android based devices, and hopefully WinMo if they ever get their act together.  Mobile programming will surely be a skill to watch in the next decade.
  • Cloud computing
    I was a little surprised to see a reference to cloud computing in a science article. But it makes sense when you think about it, because scientists need to make increasingly complex models to prove their theories and solve problems, they will need more and more processing power to do it.

    I don’t think that it will be worth it for the average “you and me” to invest time into learning how to make cloud computing infrastructures. The big 3 (Microsoft, Google, and Amazon) will commoditize these infrastructures and make them easily available … for a price of course. Learning how to make programs that thrive in the clouds however, will prove to be useful. I’ve written some about this topic recently. You can start programming in functional languages like F#, or learn how to program shaders using HLSL to teach your brain how to think in highly parallelizable terms.

Time is always the ultimate author of history, so we will have to wait and see how many of these predictions turn out to be true.  But one thing is clear, if you learn how to make games, there is a good chance you will be successful in the next decade ;-)

Comments (1)

Cleaning up after MSTest

For those of you that use MSTest, you’ve no doubt noticed a folder called “TestResults” which can get quite large.  This is because each test run copies all of the project output into that folder to store the results of the run.

Well, I updated my little open source tool to take care of it: http://vsclean.codeplex.com

As it’s traversing the directories, it will delete any of those “TestResults” folders that it comes across.  Download now!

Comments

Snap-Circuits: Review

Completed Snap Circuit

In the months leading up to Christmas ’09, I was pondering what to buy for my kids. Instead of the normal brainless and easy gifts like transformers, gi-joes, and barbies, I wanted to get them something that matters, something that will benefit them. As I browsed around the internet, I came across microscopes, chemistry kits, telescopes, bird watching kits. Those were all fine enough gifts … but they didn’t really jump out at me for some reason.  Until I found …

Snap-Circuits

“Elenco’s Snap Circuits makes learning electronics easy and fun! Just follow the colorful pictures in your manual and build exciting projects such as AM radios, burglar alarms, doorbells and much more! You can even play electronic games with your friends. All parts are mounted on plastic modules and snap together with ease. Enjoy hours of educational fun while learning about electronics. No tools required. Uses “AA” batteries. Not included.”

Wow, the thought that electronics can be packaged up and easily explained to an eight year old was fascinating. I found one at my local Radio Shack, picked it up, and wrapped it. So far I have to say that I am very impressed with the product and my kids both seem genuinely interested. I thought I was going to have to carefully walk them through it, but they have picked it up quickly and have started doing projects on their own.

The manual is fantastic, very easy to follow instructions, and great descriptions of what’s going on in the circuit.

The manual

Of course, the only drawback so far is that the batteries drain pretty quickly … I’ve already had to replace one set. However, the kids like it so much that I’m considering picking up one of the larger sets along with this awesome battery eliminator that lets you draw power from a wall plug.

I will definitely rate this a buy if you’ve got kids … or heck, even if you want to learn more about electronics yourself and don’t already have the background :-)

Comments

Semi-Literate Programming with C#

Recently, I’ve been reading the book Coders at Work, where author Peter Seibel interviews lots of well known developers.  One of the questions that he often asks is whether they have tried Literate Programming, an idea introduced by Donald Knuth in the 70s.  Although most of them say no, some of them have tried it briefly.  They usually come to the conclusion that it’s an interesting idea, but a lot of the tooling doesn’t really make it a realistic solution.

The author’s insistence at asking them about this got me thinking about some of the problems that I’ve encountered during my career.  Could literate programming be applied in this modern day and age to help solve some of the problems that we all face?

A Use Case

I started thinking about the types of code where these questions tend to come up with. It’s usually around code where business analysts make up some business rules.  Let’s use an example.  Say you work at a company that needs to creating billing statements for clients.  When you process the statements, there are a series of fees which you must attach to the bill based on certain conditions.

The rules may have been explained to the developer in a face to face meeting like this:

  • Apply a 7% tax on the principal when the client is in Florida
  • A $50 flat fee will be applied when a New York based client maintains a principal of more than $1000

So I, as a developer will scuttle away and create the program per specifications. The application goes to production and everyone is happy. Two years pass by, most of the original staff that was working when the system was originally deployed has turned over, and the new staff has a question about why some fees are being charged for a given client.

In an ideal world, the business will refer back to documentation that they created when wanting to know about the behavior of some system that you programmed. However, in the real world, a more likely scenario is that they will end up asking you over the phone about some obscure section of the code and you end up having to crack open the source to figure out what the code is doing in that piece.

The Solution?

I want a solution that lets me write code, and without manual intervention, allow other developers and the end user to understand what the business logic is doing.  Of course, most people will point to the XML documentation feature of C# along with auto-documentation products like SandCastle, and suggest that this is enough.  However, maintaining XML comments violates the “without manual intervention” part of my own requirements. It also creates output that is not really consumable by end users.

There is also another issue that most people probably don’t really think about. A lot of the code in today’s projects is not really … useful, to document. Serialization code, parsing code, data access code … most of that is pretty standard.  Developers will easily understand it assuming they already know how to use the APIs like ADO.NET, and WCF.  And users won’t care about it.  So that really just leaves the fundamental logic that is the raison d’être for your application in the first place. This is what I am interested in making easily available for a human to read.

For the solution, I wrote a simple Rule class:

public class Rule<T>
{
    private Expression<Action<T>> expression;
    private Expression<Func<T, bool>> evalExpression;
    private Action<T> compiled;
    private Func<T, bool> evalCompiled;

    public void Execute(T context)
    {
        if (this.evalCompiled(context))
        {
            this.compiled(context);
        }
    }

    public Expression<Func<T, bool>> Evaluation
    {
        get { return this.evalExpression; }
        set
        {
            this.evalExpression = value;
            this.evalCompiled = value.Compile();
        }
    }

    public Expression<Action<T>> Action
    {
        get { return this.expression; }
        set
        {
            this.expression = value;
            this.compiled = value.Compile();
        }
    }

    public override string ToString()
    {
        return string.Format("if {0} then {1}",
                                    this.Evaluation.Body,
                                    this.Action.Body);
    }
}

This class takes, as a generic parameter a context which represents one item that needs to be processed.  You will set two lambda expressions: the Evaluation, and the Action.  The evaluation will return true if the action is to be applied.  An example can be seen below:

List<Rule<BizContext>> rules = new List<Rule<BizContext>>();

rules.Add(new Rule<BizContext>()
{
    Evaluation = c => c.State == Florida,
    Action = c => c.Fees.Add(c.Principal * .07M)
});

rules.Add(new Rule<BizContext>()
{
    Evaluation = c => c.State == NewYork && c.Principal > 1000.00M,
    Action = c => c.Fees.Add(50.00M)
});

“BizContext” in the above code can contain anything that pertains to the item that needs to be processed.  In our case, the analyst’s rules say that we need to operate based on the principal and client’s state, and add fees.  So those are the properties that the context contains. Because the rules were added to a list, you can iterate through the list and call the rule class’ “Execute” method.

foreach (var rule in rules)
{
    rule.Execute(context);
}

So far, there’s nothing groundbreaking about the Rule class. I’m sure many of you have written something similar time and time again. But here’s where the literate programming comes into play. Because the “Evaluation” and “Action” methods are actually Expressions … we have access to the textual representations of the code, in addition to having the ability to execute it.

The overridden .ToString method on the class will output an easy to understand string of the business rules using actual code that will execute when it’s run. So for the two rules defined above, you can get a printout like this:

if (c.State = Florida) then c.Fees.Add((c.Principal * 0.32))
if ((c.State = NewYork) && (c.Principal > 1000.00)) then c.Fees.Add(50.00)

The end user gets a realistic printout of the actual business logic in the system on-demand; And the developer doesn’t have to do anything to update this when the business logic changes.

So there you have it; I wouldn’t exactly call it full fledged literate programming with C# in the way that it was described originally.  But I think that it embodies the qualities of literate programming, where documentation and code are one and the same. It’s a compromise, and it would be interesting to see if this approach can be implemented in a real-world scenario.

Any takers? :-)

Comments (1)