Home
[Bad advice - TBDeleted] Comments - Do you add comments for your code if it is updated?
  v7.0 Posted at 25/01/2019 2:25 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

//
// 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

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

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​

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: