Home
Comments - Do you add comments for your code if it is updated?
  v1.0 Posted at 25/04/2018 6:51 AM by Tiago Araujo

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 Sub iStopwatchOptionsForm_Resizing(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Resize
'If Me.WindowState = FormWindowState.Minimized Then
'Me.Hide()
'End If
'End Sub

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 Sub iStopwatchOptionsForm_Resizing(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Resize
'If Me.WindowState = FormWindowState.Minimized Then
'Me.Hide()
'End If
'End Sub

Figure: Good example in VB.NET

Private Sub iStopwatchOptionsForm_Closing(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
'Don't close this form except closing this application - using hide instead;
If Not Me.m_isForceClose Then
If Me.IsOptionsModified Then
If MessageBox.Show("Do
you want to save the changes?", Me.GetApplicationTitle, MessageBoxButtons.YesNo,
MessageBoxIcon.Warning) = DialogResult.Yes Then
Me.SaveOptions()
End If
End If
End If
End Sub

Figure: Bad example in VB.NET

Private Sub iStopwatchOptionsForm_Closing(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
'Don't close this form except closing this application - using hide instead;
If Not Me.m_isForceClose Then
'<added by FW, 11/10/2006>
' Remind saving the changes if the options were modified.
If Me.IsOptionsModified Then
If MessageBox.Show("Do you want to save the changes?", Me.GetApplicationTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = DialogResult.Yes Then
Me.SaveOptions()
End If
End If
'</added>
...
End If
End Sub

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.