CCC2: InitializeComponent()

Published 28 April 04 02:14 PM

Call it a Clearest Code Challenge: What should InitializeComponent() look like?  What’s the best code you can imagine, that the WinForms designer should generate?

 

Let’s take a simple, concrete case: a form with an OK button. The button is anchored at the bottom right.

 

Let’s also pretend that the WinForms team has no trouble coding solutions to intractable problems.  For example, if you propose an InitializeComponent that solves the Halting Problem, your form will still show correctly in the designer.  This should free us from worry about what code analysis tools are capable of.

 

My last post gives us the seed code – the solution we produce today in Whidbey. 

 

May the Refactoring begin!

Comments

# Dave said on May 4, 2004 3:05 PM:
You ask for the best code, and code which could be intractable. So I'm assumining that you're actually asking for the 'most readable' code.

Given that assumption, I'd say promote XML to a first class language construct (X#, Xen), and render InitializeComponent as XML. That'd look pretty nice.

But partial classes are great too. :)
# jaybaz [MS] said on May 4, 2004 4:30 PM:
Woo, a response!

I didn't mean to ask for intractable code. I'm just saying you can ignore the limitations of the designer.

XML is probably the right answer. I had a particular way I wanted this discussion to go, and XML completely diverts it & makes much more sense.

My goal was to motivate a discussion about OO code. I imagined creating a nested class called "OKButton" that encapsulated the properties and behaviors of the button.

Then I wanted to talk about how you might refactor from InitializeComponent to a nested class.

I also wanted to rant about VB's "with" statement, and make the case that you only need "with" if you aren't writing good OO code.

But you outsmarted me!
# jaybaz MS WebLog CCC2 InitializeComponent | My Site said on June 1, 2009 12:00 AM:

PingBack from http://patiochairsite.info/story.php?id=318

New Comments to this post are disabled

This Blog

Syndication

Page view tracker