0

With the modern IDEs such as VS 2012, is there a significant performance difference in going with code created by visual tools (such as Visual Studio, Qt, etc.) rather than writing the code from scratch? I remember when I first tried Dreamweaver back in 2003, I couldn't stand the fact that it bloated the code with nonsense. From there on I've had a distrust with visual-style creation of applications. Now that I'm picking up pace in computer programming, I would like to optimize the way I do things. Due to the fact that I don't have enough experience, I can't answer my own question.

I am not looking for preference in one over the other, so this is not a discussion of which one is better. I am more interested in answers from those who have noticed the difference in performance between the two ways of creating applications.

EDIT (08/18/2013): Besides the wonderful answers that people gave me, I thought I'd add this for anyone who's researching into performance. I've been reading Beginning Visual C# 2012 Programming and in there I found something very important and impressive:

As with partial classes, partial methods are useful when it comes to customizing auto-generated or designer-created code. The designer may declare partial methods that you can choose to implement or not depending on the situation. If you don’t implement them, you incur no performance hit because effectively the method does not exist in the compiled code.

So, all that extra "junk" that is being created won't effect the performance if no implementation occurred. Things have come a long way and I couldn't be happier in that regard.

B.K.
  • 9,982
  • 10
  • 73
  • 105

3 Answers3

1

I'd actually say no and yes at the same time :)

No because the Designer is actually just doing stuff you would have done anyway, just automatically. Take a look at a simple Form created via the Designer.

First of all the partial class itself is compiled at compile-time and maps up the same IL result. So no loss here. Take a look at this post regarding that.

Second the disposing is something being recognized as good practice to not populate your memory endlessly.

And last the InitializeComponent stuff only adds the absolutely necessary content. If you drag any Control on the surface, even that gets initialized with the necessary properties and typically nothing else.

The reason why I sad yes too is that depending on the control there may be added some things, that you anyway expect to change in your code, like the Text property or similar. So those are few lines that could be skipped. But in general I guess it should be ok and no big difference either doing it manually or via code.

partial class SampleForm
{
    /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.ComponentModel.IContainer components = null;

    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
    protected override void Dispose(bool disposing)
    {
        if (disposing && (components != null))
        {
            components.Dispose();
        }
        base.Dispose(disposing);
    }

    #region Windows Form Designer generated code

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
        this.components = new System.ComponentModel.Container();
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.Text = "SampleForm";
    }

    #endregion
}
Community
  • 1
  • 1
zewa666
  • 2,593
  • 17
  • 20
  • Thank you for the great information. The points you brought up, plus the reference to the other post brought a lot of relief and understanding. – B.K. Aug 16 '13 at 00:54
1

Why do you worry about performance in that part of code? Graphical designer just string together existing ui building blocks. That's never performance critical. Either the building blocks are fast enough to use, or they are not. A mouse click on a button isn't animated better or faster when you hand-optimize the button's creation and positioning in your gui. Maybe you can worry about code size. There it might be possible to optimize a little. But I doubt it.

Greenflow
  • 3,935
  • 2
  • 17
  • 28
0

with Qt Creator, the autogenerated code is actually quite readable and looks pretty much the way you would expect it to if you had coded it by hand. That being said, I still hand code stuff.

daj
  • 6,962
  • 9
  • 45
  • 79