
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:
- Noise comments: They just repeat what the code says and does not increase the readability and should be avoided.
- Placeholder comments: They are note to your future self.
- 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