My Best Practices for Writing web Applications

A few people have asked me what patterns do I use when developing web applications so I figured I would take a few minutes to write them down. Please note that these are the practices I have found work great for me. Warning: one size does not fit all

First let me say that I’m a pragmatist at heart, and I write software for a living, so I must find a balance between perfection, maintainability, and profitability.

I’m sure there are other people out there that have created their own development style that works very well for them, for me however, after using most of the shiny three letter patterns, I have found that these principles give me the best of both worlds, RAD development and a Maintainable application. And best of all they help me enjoy my job.

1. Hand Crafted Model

I use POCO objects as my model. These objects are hand crafted by me instead of being generated by a tool, and they are the foundation of my app.

2. No ORM

I do not use an ORM, but rather I use my own tool BigfootSQL. It gives me the best of worlds, complete control over my SQL while at the same time saving me from all the grunt work of object Hydration and query execution. I have been developing software for a while, and have fallen victim to the Microsoft fascination with changing data access technologies with almost every release. My strategy is to try to stay as close to SQL as possible while minimizing the manual work, BigfootSQL does this for me.

3. Operation based validation

I validate at the point of the operation execution, rather than performing model based validation. When validation must be shared across operations then a validation helper is employed in order to share this logic. Models rarely if ever are validated in a vacuum, validation changes depending on the type of operation being performed and depending on more than a single model object. Operation validation on the other hand, validates at the operation end, it simply looks at what the action itself is, and validates the action. This way you can effectively and simply validate against multiple types of operations against your object model while keeping your validation and business rules simple. It also keeps you from writing validation code that you won’t use. To achieve this, I use a modified version of TNValidate. TNValidate is an open source fluid interface style validation framework that makes validating my objects extremely simple. I’ve repackaged my modified version of TNValidate into BigfootSQL. I also use a set of Post helper methods that help me retrieve the values from a post while providing simple type validation and required validation. You can find my PostHelper class in my open source project BigfootMVC, this is an ongoing compilation of helper methods I use for MVC style development. I use these helpers when developing for classic ASP.NET, ASP.NET MVC, and DotNetNuke module applications.

4. Highly specific and smart ViewModel

For every view, I create a ViewModel whose job it is to handle all data requirements and operations for the view. These VMs are smart and self aware, they have static factory methods for creating themselves, and also handle all view operations which get executed by the Controller. They talk to the Repository to get data and execute operations against the Database. They help me keep my controllers thin by delegating a lot of the operations responsibility closer to where the action is.

5. No IoC container

It is ok to take a dependency on your own code. Most of of the time we find ourselves using IoC simply for the reason of making our code testable. Instead of adding complexity to the code to make it testable, I use a smart mocking framework that allows me to effectively mock any kind of dependency without having to use the IoC pattern, I use JustMock by Telerik. This allows me to write my applications in a much simpler way while still keeping them completely testable. I know this is a religious topic for a lot of people, however in my experience, after using several IoC containers, you are simply adding undue complexity to 90% of your apps. I do acknowledge there is a 10% that need it, all I’m saying is, use it where required, be a craftsman, use the right tool for the right job.

6. Highly Helped Views

I have developed a set of Html helpers that allow me to perform most view operations, including complex ajax operations, in a very simple way. They help me be extremely productive while creating highly responsive web interfaces. As a developer of some experience with web development, highly responsive (ajax) web interfaces and productivity do not always go hand in hand. I set out to develop a rich set of helpers that allow me to perform the 80% case scenarios with one line or less of strongly typed code. I open sourced all of these helpers under my ongoing BigfootMVC project.

7. Take a dependency on JavaScript

For web applications, I take a dependency on JavaScript. This allows me to deal with older less capable browsers much more efficiently. While not all sites can do this, most applications are safe to take a dependency on JavaScript. I also use a strong master page that helps me deal with the browser differences. I use jQuery, Selectivizr, and a few other tricks to make working with IE6 and other non CSS3 HTML5 browsers much easier and less painful.

8. Strong CSS reset with a rich set of helper classes

I have published the CSS framework that I use, BigfootCSS, it is a compilation of best practices I have found around the web published by really smart people like Eric Meyer, Paul Irish, and a few others. I have also loaded it with a lot of helper classes that I use over and over again in more utilitarian application interfaces. For me it provides a good middle ground between inline styles and 100% custom CSS. I reserve the use of custom CSS classes in my design for what is truly custom, and use helper classes for the common operations.

 

Summary

If I had to sum up my strategy in one word – or one acronym rather – I would say “KISS”. Above all keep it simple, that is the secret to productivity and maintainability.

So that’s it really, a few simple no non-sense principles that make my life easier when it comes to developing web applications.

Hope this helps!

Mitch

About these ads

2 responses to this post.

  1. I must show my admiration for your kindness in support of those people that actually need assistance with this subject matter. Your very own dedication to passing the message across became really good and have truly empowered professionals just like me to achieve their ambitions. Your interesting useful information indicates this much a person like me and especially to my fellow workers. Thanks a lot; from all of us

    Reply

  2. I had been wondering if your web host is OK? Not that I’m complaining, but slow loading instances times will sometimes affect your placement in google and can damage your high-quality score if advertising and marketing with Adwords.

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: