From Scott Allen's C# Fundamentals Part 2 course on Pluralsight -
Rule #10: Avoid Regions - as they are typically used to hide ugly code or classes that've exploded in size or responsibility. Think if you should break the regions into seperate classes
Rule #9: Use exceptions for errors..instead of status code or booleans...but not for control flow
Rule #8: Avoid boolean parameters
Rule #7: Avoid too many parameters - beyond 4, consider grouping
Rule #6: Warnings are errors - Go to a Project's Properties and in the Build tab of the dialog box that opens up, change "Treat warnings as errors" to All from the default None
Rule #5: Encapsulate complex expressions - Instant recognition is good
Rule #4: Try to avoid multiple exits - have just one
Rule #3: Try to avoid comments - A meaningful method name is more effective than comments. Triple slash comments in VS are ok as they help in documentation of an API. Other developers can see your comments through Intellisense when they reference your assembly.
Rule #2: Keep methods short - general rule of thumb: 1 to 10 lines
Rule #1: Keep classes small
+ The foundation for most C# coding standards is Microsoft's "Design Guidelines for Developing Class Libraries"
+ ReSharper VS Plugin & StyleCop can help you enforce naming conventions
+ Names contain meaning & adding meaning to code is what readability is all about - use meanigful names
+ Embedding type in the name of a variable is not a good idea especially for primitive types. Name should indicate what an variable or object can do & what it represents.
+ How to improve readability of your code - read other people's code to figure what is good & what is bad. Be introspective.
0 comments:
Post a Comment