📎 Webclip
EP 66: Clean Code Tips for .NET Developers - Part I
The post collects several clean code habits for .NET work. It favors names that make code self-explanatory, recommends throwing exceptions instead of returning null in some cases, and encourages smaller classes with one reason to change. It also points to using existing logging tools, better IDE support, and project-wide configuration.
Reading notes#
- Meaningful names make code easier to understand and reduce the need for extra comments.
- Returning null can lead to NullReferenceException errors and makes callers check for null before using the value.
- A method or class should stay focused, with separate classes for validation, payment, inventory, email, and order processing when concerns are different.
- There is no hard rule for method length, but 20 to 40 lines is described as enough for a method.
- Reinventing the wheel wastes time and effort when logging is already available through ILogger and configured tools.
- Using the right IDE features helps with syntax highlighting, code completion, and early error checking.
- EditorConfig and project settings can apply common code rules across .NET projects.
