Blog Stats
  • Posts - 14
  • Articles - 0
  • Comments - 6
  • Trackbacks - 0

 

Wednesday, November 28, 2012

Comments in code


It is a good practice to leave comments in your code.  Knowing what the hell you were thinking or later intending can be salvation for yourself or the poor soul coming behind you.  Comments can leave clues to why you chose one approach over the other.  Perhaps staged re-engineering dictated that coding practices vary.

One thing that should not be left in code as comments is old code.  There are many free tools that left you version your code.  Subversion is a great tool when used with TortoiseSVN.  Leaving commented code scattered all over will cause you to second guess yourself, all distraction to the real code, and is just bad practice.

If you have a versioning solution, take time to go back through your code and clean things up.  You may find that you can remove lines and leave real comments that are far more knowledgeable than having to remember why you commented out the old code in the first place.

LastPass


LastPass.com.  Get it, use it, save your sanity.  This is a great program to be able to remember one hard password and be able to generate several other hard passwords for each site, application, or sign in you have to use.  Highly Recommended.

Old school trick that I forgot


If you have to support some older Winforms you might like to remember this.  When opening a MessageBox to display that the user entered incorrect information, if you are doing so from a dialog, catch the DialogResult of the MessageBox and then set 

this.DialogResult = DialogResult.None;

 to prevent the dialog from closing if you want the user to try again.  Otherwise, it will close the dialog box and return to the section of code that called it.

Note:  You do not have to catch the DialogResult from the MessageBox.  You can still set this after the return from the call to the MessageBox.  Just make sure to do either but exiting the body of the dialog itself.
 

 

Copyright © DavidMadden