Is the WinForms Designer Evil?

Over the past several months I’ve been getting up to speed on WinForms.  For the previous 5+ years I’ve been doing web based software development.  During those wonderful years I created many little utilities using WinForms (or VB6!?!?).  Even the most complicated of my WinForms experiments was peanuts in comparison to what any “real” WinForms developer has developed. 

During my time in the web world I learned one very important lessen: NEVER use the Web Forms designer!  Not only does it create horrendous HTML, but it also deletes code, removes event handlers, and causes overall havoc on your project.  Luckily VS 2005 fixes most, if not all, of those problems.

Now that I’ve gotten off topic a bit lets get back to the question at hand….is the WinForms designer evil? 

The WinForms designer makes developing complex forms feel quick and painless.  The drag-and-drop’ability allows you to throw together new forms in no time flat.  It allows you to hook up event handlers and plug in the code that should be executed when those events fire using a couple mouse clicks.  What this all leads to is a great environment for building prototype applications.   What it doesn’t lead to is well architected WinForm applications.  Just using the WinForms designer doesn’t do anything to help with the testability of your application.  If your application can’t be tested it’s not well architected.

The hardest thing to unit test in an automated way is a Gui.  Do yourself a favor and DON’T use the WinForms designer.  Think of ways you can make your application testable.  Evaluate what you should do in the designer and what you shouldn’t.  If the things that you deem as “should do in the designer” outweigh the things that you deem “should not be done in the designer” then start your list over.  Repeat until very few things are in your do in the designer list.  While I don’t think the WinForms design is outright evil I do think it should only be used in moderation.  Use MVP, don’t use that designer.

# re: Is the WinForms Designer Evil?

Tuesday, November 15, 2005 11:41 PM by JFo    
I totally agree with you that the designer doesnt get you to that next 50 lines of code - that is something we're seriously looking at addressing in the future.

However you skip over an important point - the designer generated code (for the most part - fingers crossed) points you to the best practice for operating with the controls themselves - e.g. using AddRange, or SuspendLayout and ResumeLayout.

I've seen some pretty bad hand written code in my time, usually it was much simpler to do something if someone had just spent a few minutes in the designer getting to work correctly rather than hand-coding.

Chuck has also made some interesting observations about this very topic:

http://www.removingalldoubt.com/PermaLink.aspx/fe06fae0-3fb8-483f-8b27-f9361c60d022


# re: Is the WinForms Designer Evil?

Tuesday, November 15, 2005 11:42 PM by JFo    
I totally agree with you that the designer doesnt get you to that next 50 lines of code - that is something we're seriously looking at addressing in the future.

However you skip over an important point - the designer generated code (for the most part - fingers crossed) points you to the best practice for operating with the controls themselves - e.g. using AddRange, or SuspendLayout and ResumeLayout.

I've seen some pretty bad hand written code in my time, usually it was much simpler to do something if someone had just spent a few minutes in the designer getting to work correctly rather than hand-coding.

Chuck has also made some interesting observations about this very topic:

http://www.removingalldoubt.com/PermaLink.aspx/fe06fae0-3fb8-483f-8b27-f9361c60d022

Post a Comment

 
 
Prove you're not a spammer: 
2 + 2 =