Saturday, May 5, 2012

Validation! So simple, yet so complicated (part 2)...

So lets discuss some more validation!

In my previous post, I discussed the last line of defense in your application, exceptions. throwing your own exceptions lets you as the developer say "Woah! I want to stop this before it fails spectacularly, leaving me an awful mess to clean up." 

Thats well and good, but the best solution is to integrate your validation as closely to the user input as possible. The faster a user know's what they are doing wrong, the better. That's where user experience development and basic input validation truly shine.

Microsoft gives you tools to do this in all of their frameworks:

  • ASP.net has a bunch of different techniques:
  • WPF can be directly integrated with your exception validation, but I would recommend using the IDataErrorInfo. here is a great article that describes how to implement this feature!
Lastly, the best way to solve strange validation issues is to design your UI in a way that naturally leads the user to enter valid input. Most call this the funnel of success, but a great place to read more about how to design a successful UI, I highly recommend reading Jakob Neilson's http://www.useit.com/ site. It may not look pretty, but it's content is exceptionally helpful when trying to understand why a radio button list might be better than a drop down list, or when you should decide what UI should be displayed.

Always keep validation of inputs in mind no matter what layer of an application you are working on, because whether your user is a PEBKAC mashing their face against a keyboard, or a brand new developer who just doesn't know how your library works, validation is the way we convey to them, hey, ID10T: Something is wrong.

No comments:

Post a Comment