My own private WTF?

Thursday 31 March 2005

As I've mentioned, I've taken over responsibility for a body of C# code. The layout code is filled with stuff like this:

this.Size = new Size(this.Size.Width,
   this.widgetsLabel.Location.Y + this.widgetsLabel.Size.Height);

To paraphrase Tevye, would it have spoiled some vast eternal plan to write this instead?:

this.Height = this.widgetsLabel.Bottom;

I spent quite some time today applying shrinking transformations:

x.Size.Height                             -->  x.Height
x.Location.Y                              -->  x.Top
x.Top + x.Height                          -->  x.Bottom
x.Size = new Size(x.Width, y);            -->  x.Height = y;
x.Location = new Point(x.Location.X, y);  -->  x.Top = y;

Believe me, it's much more readable afterwards! Of course, I've a sneaking suspicion that a lot of this layout code could just be chucked by setting proper constraints in the forms designer! To quote another movie character, I can't think about that today, I'll think about that tomorrow.

I've slightly edited this post to remove asides about developers that were distracting from my point. Reactions from readers about those comments have also been removed.

Comments

[gravatar]
Jeff Kowalczyk 11:22 PM on 31 Mar 2005

Looks like their code was generated by a GUI page design mode.

[gravatar]
Kevin 9:15 AM on 1 Apr 2005

"You are in a maze of twisty little passages, all different."

[gravatar]
Damian Cugley 1:15 PM on 8 Apr 2005

If you try to set widget.Location.Y I think it complains that Y is a read-only property, as I recall. Perhaps whoever wrote this assumed that the same would apply to widget.Top and never checked once they had found an incantation that works. I think I've done the same with some of this widget stuff.

Add a comment:

name
email
Ignore this:
not displayed and no spam.
Leave this empty:
www
not searched.
 
Name and either email or www are required.
Don't put anything here:
Leave this empty:
URLs auto-link and some tags are allowed: <a><b><i><p><br><pre>.