Wednesday, July 27, 2011

Coder to Developer: Tools and Strategies for Delivering Your Software by Mike Gunderloy : Introduction and Chapter 4

The author talks about defensive coding in this chapter whose goal is to write code that makes it easy to find problems and make modifications.

The author discuss about usage of assertions to detect errors in code. The author provides following two guidelines:
  • Assertions should not have side effects.
  • Avoid assertions to test compiler/language issues
The author then talks about exceptions, the exception mechanism in C#, the reason for creating custom exceptions and the guidelines for creating custom exceptions in C#. The author then implements his own custom exception for Download Tracker application. The author then provides following guidelines for good exceptions:
  • Exceptions are for exceptional situations
  • Don't create unnecessary custom exceptions
  • Constructors with a string value should be used
  • Pass exception from low level routine to higher level routine with enough information
The author then examines the debate of whether to use comments or have self-documenting code. The author likes the first approach better and classifies comments in following different categories:
  1. Noise comments: They just repeat what the code says and does not increase the readability and should be avoided.
  2. Placeholder comments: They are note to your future self.
  3. Summary and Intent comments: Summary comments summarize a lot of code in short English statements. Intent comments do not explain what the code does, it explains why it does it in a particular manner.

No comments:

Post a Comment