Wednesday, May 19, 2010

Exception Driven Development and CodeSmith Insight

f customer facing issues are your top priority, then you are already adhere to the primary principle of Exception Driven Development.

Exception Driven Development

It's a pretty simple concept: Collect application data, especially regarding errors and crashes, and then focus on fixing those problems that your users are actually experiencing.

Following good development practices such as Test Driven Development, Automated Deployment, and rigorous QA, help us develop more reliable software. While these efforts can cost additional time and money, it is almost universally agreed that the return on investment (happy users working with a solid product) is worth every penny. So given all the things we do to prevent bugs from getting released, when a bug does finally make it into production, not fixing it right away would be negligent, irresponsible, and it would undermine all the work put into preventing bugs in the first place.

A great example of the ROI (return on investment) from using EDD is the Windows Error Reporting service. Microsoft has been recording errors from both their products and others for years now, and after analyzing the data they have come to some compelling conclusions:

"80 percent of customer issues can be solved by fixing 20 percent of the top-reported bugs. Even addressing 1 percent of the top bugs would address 50 percent of the customer issues."

What does all this mean? It means it's a really good idea to log errors, respond to user defect reports, and basically do everything you can to fix bugs that users are experiencing, ASAP!

So, it's good to ship buggy code? No, absolutely not! ...but sooner or later, it is going to happen; and when it does, it is your job to improve your software.

How do we do this? Use some form of exception and error reporting software. You need a central location to aggregate your application's errors and crashes.

While the concepts of EDD are not rocket science, the task can still take a little bit of work to achieve. Having the correct tools readily available makes the job much easier...

1) Error Reporting Services

I am saying that you need something to report errors, and then I'm suggesting that you probably want a preexisting tool to do that. Implementing your own solution to log errors is probably tempting, but it's not often the best idea. A few common flaws include: increasing time to market, a lack of standardization between products and other tools, and the ironic bugs in your bug tracker.

For reference, here are just a few of the better error reporting tools out there:

  • ELMAH
  • Exceptioneer

A major problem with the simplest (and thus most common) implementation of error reporting software, is that often it's just a log...a log that quickly starts to resemble the bottomless pit in the basement of any fantasy dungeon; you know, the one where even the bravest warriors, and savviest developers, fear to tread. (Please note, I am not trying to imply that the tools I mentioned above do this, I'm just saying that logs eventually stack up.)  A good solution to this is to organize captured errors into an issue tracking system...

2) Issue Tracking

Often issue tracker software gets merged with project management software, so without going into it too much I'll just say a few quick things:

  • Different exceptions may be the same bug.
  • Twenty occurrences of the same bug are still just one bug.
  • Two hundred occurrences of one bug does not necessarily make it higher priority than the twenty occurrences bug.

Having a system to help organize and prioritize your bugs is pretty vital to getting them fixed.

So far we have talked about capturing errors and organizing them, but what about bugs that don't crash or throw exceptions?

3) Help Desk

Not all bugs in software cause the application to blow up, nor do they always throw exceptions. Sometimes a human being (not something that we are used to working with in software) actually has to tell you "Hey, X is not working!" This kind of communication can be facilitated by email, feedback services, etc. The bottom line is that you need a way to collect feedback (include defect reports) from users; and then, ideally, you want to sync that information with whatever you are using to track issues/tasks.

Here are a few good help desk systems:

  • FogBugz
  • Smarter Track

So, if you like the concepts behind EDD, but don't like the idea of having to pay-for/integrate-with/learn-how-to-use/login-to/aggregate-data-from three different systems *GASPS FOR AIR*, than I have just the product for you!

CodeSmith Insight

A jack of all aforementioned trades, and a master of feedback aggregation, CodeSmith Insight was designed to unite these types of software systems.

Error Reporting Service

CodeSmith Insight provides a client that integrates with any .NET application. You just drop in one assembly reference, and add a few simple lines into your app.config, and then Insight will be wired up to automatically report all unhandled exceptions. The CodeSmith Insight client also makes it extremely easy to report any other information you want, whether that be creating a new case in the system, or adding additional information to a preexisting case.

Issue Tracker

All cases reported to CodeSmith Insight, whether they be crash reports, user feedback, or emails, are all saved in a central database hosted in the cloud. Insight automatically stacks duplicate errors that it receives, as well as allows you to merge issues together. All cases are completely searchable, and include a slew of information, including a complete history of actions taken on the case.

Help Desk

CodeSmith Insight can send and receive email, and it offers a robust email client built right into it's web UI. After a case is created in the system (whether that be a crash report or an email), you can then respond directly to a user regarding that case, and then go back and fourth from there. You can even send an update to a group of users experiencing the same issue and let them know the issue has been fixed.

I realize that as a CodeSmith employee I probably have a little bit of bias on subject, but I can say with all honesty and sincerity that CodeSmith Insight really is the perfect tool for Exception Driven Development. But you don't have to take my word for it; CodeSmith Insight is currently in beta, and is FREE! Go check it out, and decide for yourself.

Monday, May 3, 2010

MVC 2 Client Side Model Validation with ExtJS

One of the most exciting new features in MVC 2 is "Enhanced Model Validation support across both server and client". The new enhanced support allows for client side validation to be dynamically generated into a view quickly and easily using DataAnnotations attributes on models. This means that by simply dressing up your model properties with attributes, your web pages can instantly have dynamic client side validation; all generated and maintained for you by the MVC framework!

MVC 2 enhanced model validation really is a terrific new feature...so, what's the problem? Microsoft uses JQuery, we use ExtJS.

We here at CodeSmith absolutely love MVC, but many of features are designed to use JQuery, and we (for several different reasons) prefer to use the ExtJS Framework. This means that (as it stands) to use both we must reference both, and no one wants to download two complete AJAX frameworks just to view one webpage.

Good news, we fixed that!

Introducing: Ext.ux.MvcFormValidator

The MVC client side form validator dynamically generates a small blob of configuration for each form, and stores them in window.mvcClientValidationMetadata. Once the page loads up, the client side validator framework loads all these configs, and then starts monitoring the specified forms for validation.

What we have done is created an alternative form validation context (modeled after Sys.Mvc.FormContext) that loads the validation configuration, and requires no changes in the MVC generated code, but uses ExtJS as it's back end. This means that the only thing you have to do is reference Ext.ux.MvcFormValidator.js, and it will enable you to use the ExtJS Core for form validation instead of having to import MicrosoftMvcValidation and the other Microsoft AJAX libraries.

Features

  • Requires only the ExtJS Core.
  • Implements all four default validators: Required, Range, StringLength, RegularExpression
  • Supports integration of custom validators with almost no code change.
    • Just update Sys.Mvc.ValidatorRegistry.validators to call Ext.Mvc.ValidatorRegistry.validators
  • Displays field messages as well as summary.
  • Extends Ext.util.Observable and uses events.
  • Lightweight; less than 300 lines of code.

Downloads

Ext.ux.MvcFormValidator.js: http://codesmith.googlecode.com/files/Ext.ux.MvcFormValidator.js
Demo Solution: http://codesmith.googlecode.com/files/ExtUxMvcFormValidationDemo.zip

Example

Model

public class ValidationDemoModel
{
    [Required]
    [StringLength(10)]
    public string Name { get; set; }

    [Range(10000, 99999)]
    public string ZipCode { get; set; }

    [RegularExpression (@"\d{3}[-]?\d{3}[-]?\d{4}", ErrorMessage="The field Phone must be valid phone number.")]
    public string Phone { get; set; }

    [AcceptBox]
    public bool Accept { get; set; }

Site.Master

<script src="/Scripts/ext-core.js" type="text/javascript"></script>
<script src="/Scripts/Ext.ux.MvcFormValidator.js" type="text/javascript"></script>
<script src="/Scripts/CustomValidators.js" type="text/javascript"></script>

View

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <h2>Validation Demo</h2>
        <% Html.EnableClientValidation(); %>
        <% using (Html.BeginForm()) { %>
        <%= Html.LabelFor(m => m.Name) %>:
        <%= Html.TextBoxFor(m => m.Name)%>
        <%= Html.ValidationMessageFor(m => m.Name)%>
        <br />
        <%= Html.LabelFor(m => m.Phone) %>:
        <%= Html.TextBoxFor(m => m.Phone)%>
        <%= Html.ValidationMessageFor(m => m.Phone)%>
        <br />
        <%= Html.LabelFor(m => m.ZipCode) %>:
        <%= Html.TextBoxFor(m => m.ZipCode)%>
        <%= Html.ValidationMessageFor(m => m.ZipCode)%>
        <br />
        <%= Html.LabelFor(m => m.Accept) %>:
        <%= Html.CheckBoxFor(m => m.Accept)%>
        <%= Html.ValidationMessageFor(m => m.Accept)%>
        <br />
        <input type="submit" value="Submit" />
        <%  } %>
</asp:Content>

Controller Action

[HttpGet]
public ActionResult ValidationDemo()
{
    var model = new ValidationDemoModel();
    return View(model);
}

Custom Validator

Ext.Mvc.ValidatorRegistry.validators["acceptbox"] = function (rule) {
    return function (value, context) {
        return context.fieldContext.elements[0].checked === true;
    };
};

Real Time Web Analytics