Home
Comments - Do you add comments for your code if it is updated?
  v5.0 Posted at 2/08/2018 5:06 PM by Partho P. Das

​​​​​​It's also important that you have a consistent code comment for your updating, which can be used by other developers to quickly determine the workings of the updating.​​

Example of commenting a method, it is strongly recommended that you add an adequate comment for your updating.

private void iStopwatchOptionsForm_Resizing(object sender, System.EventArgs e) {
    if (this.WindowState = FormWindowState.Minimized) {
        this.Hide()
    }
}

Figure: Bad example in VB.NET

//
// Commented - we don't need to hide this from when it is minimum size, just leave it on taskbar.
// FW, 11/01/2018
//
private void iStopwatchOptionsForm_Resizing(object sender, System.EventArgs e) {
    if (this.WindowState = FormWindowState.Minimized) {
        this.Hide()
    }
}

Figure: Good example in VB.NET

private void iStopwatchOptionsForm_Resizing(object sender, System.EventArgs e) {
    // ​Don't close this form except closing this application - using hide instead;
    if (!this.m_isForceClose) {
        if (this.IsOptionsModified) {
            if (MessageBox.Show("Do
you want to save the changes?", Me.GetApplicationTitle, MessageBoxButtons.YesNo,
MessageBoxIcon.Warning) = DialogResult.Yes) {
                this.SaveOptions()
            }
        }
    }
}

Figure: Bad example in VB.NET

private void iStopwatchOptionsForm_Resizing(object sender, System.EventArgs e) {
    // Don't close this form except closing this application - using hide instead;
    if (!this.m_isForceClose) {
        // <added by FW, 11/10/2006>
        // Remind saving the changes if the options were modified.
        if (this.IsOptionsModified) {
            if (MessageBox.Show("Do
you want to save the changes?", Me.GetApplicationTitle, MessageBoxButtons.YesNo,
MessageBoxIcon.Warning) = DialogResult.Yes) {
                this.SaveOptions()
            }
        }
        // </added>
    }
}

Figure: Good example in VB.NET ​

Related rules

    Do you feel this rule needs an update?

    If you want to be notified when this rule is updated, please enter your email address:

    Comments:

    Note: Social Media login for Yotpo is not working in IE or Safari, please use Chrome. We are waiting for Yotpo to fix it.