The article discusses real-world coding issues encountered in a contract project. Part 3 covers common coding issues related to design, diagnostics, and other areas, such as globalization, code duplication, and Linux-based development challenges. It emphasizes the importance of code quality, performance, and prioritizing code reviews to ensure a maintainable and efficient solution.
Category: Defensive Programming
Microsoft .NET Code Analysis: Use Auto-Implemented Property
The article discusses the use of auto-implemented properties in Microsoft .NET code analysis. While the author generally advises against their excessive use, they highlight a real-world example where utilizing an auto-implemented property is advantageous due to its conciseness, readability, encapsulation, and ease of maintenance. The author recommends using tools like CodeRush from DevExpress to streamline the refactoring process.
Microsoft .NET Code Analysis: Validate Arguments of Public Methods
The author highlights the critical issue of insufficient argument validation in public methods, drawing on 20 years of experience. They emphasize its importance for maintaining encapsulation in object-oriented programming. A significant finding revealed 700 instances of this oversight, showcasing the necessity for proper validation to ensure data integrity. Recommended resources are mentioned for further learning.
Coding Faster with dotNetTips.com Spargine 6: Aug 2023 Release
Spargine 6 (v2023.6.8.1) is now available, an open-source project offering NuGet packages for .NET 6 & 7 with new classes, methods, and significant speed improvements. The release introduces a custom result type for method returns, offering an alternative to exceptions, empowering software engineers to boost application performance.
Microsoft .NET Code Analysis: Ensuring Proper Resource Management – Implementing IDisposable for Disposable Objects
One persistent issue I have noticed throughout my experience working on projects for the past 12 years is the improper handling of disposable objects and the lack of implementation of IDisposable for types with disposable fields. Failing to handle these objects correctly can lead to virtual memory leaks and subsequently bring down applications and services. Unfortunately, this problem occurs far too frequently.
Microsoft .NET Code Analysis: Recognizing the Significance of ConfigureAwait in Reusable Assemblies
Check out this article on the importance of ConfigureAwait() in reusable assemblies. It discusses performance, avoiding deadlocks, and scalability.
Microsoft .NET Code Analysis: UTF-7 Encoding Is Insecure
In the codebase I reviewed for this article, I found several instances where UTF-7 encoding was used, which is no longer recommended and is prohibited by many specifications. It is important to avoid using UTF-7 encoding that is explained in this article.
Microsoft .NET Code Analysis: Always Add Braces {} in C#
The discussion centers around the usage of braces in C# statements and their criticality in maintaining code readability and structure. Using braces helps delineate code blocks, groups statements, controls flow and scope and avoids unintended errors. The author promotes regular refactoring with tools like CodeRush and suggests integrating specific settings into the EditorConfig file. He also recommends his books for additional guidance and insights.
Microsoft .NET Code Analysis: The Rijndael and Rijndaelmanaged Types Are Superseded
The Rijndael and RijndaelManaged types in .NET have been replaced by the more secure and efficient AesManaged type since September 2021. It is advised to use AesManaged instead of RijndaelManaged for AES encryption due to better compatibility and support for required block and key sizes. The provided code example demonstrates the usage of both encryption algorithms, and it is crucial to stay updated with secure algorithms to avoid potential fines during security audits.
Microsoft .NET Code Analysis: Enums Should Always Have a Zero Value
When reviewing code, the absence of a default value for Enums is a recurring issue. Assigning a zero value, like "NotAuthorized," provides a valid initial state, enables implicit conversions, and aids in error handling. Proper Enum design is vital for effective coding practices. Always validate Enum values using methods like Enum.IsDefined.

You must be logged in to post a comment.