Scott Allen's 10 favorite C# rules for developing software


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.

Comments

Popular posts from this blog

Maven Crash Course - Learn Power Query, Power Pivot & DAX in 15 Minutes

"Data Prep & Exploratory Data Analysis" course by Maven Analytics

Oracle Cloud Infrastructure 2024 Generative AI Professional Course & Certification Exam (1Z0-1127-24)