Do you avoid Empty code blocks?
Updated by Brady Stroud [SSW] 1 year ago. See history
123
<introEmbed
body={<>
Empty Visual C# .NET methods consume program resources unnecessarily. Put a comment in code block if its stub for future application.
Don’t add empty C# methods to your code. If you are adding one as a placeholder for future development, add a comment with a TODO.
Also, to avoid unnecessary resource consumption, you should keep the entire method commented until it has been implemented.
If the class implements an inherited interface method, ensure the method throws NotImplementedException.
</>}
/>
public class Example{public double salary(){}}
❌ Figure: Figure: Bad Example - Method is empty
public class Sample{public double salary(){return 2500.00;}}
✅ Figure: Figure: Good Example - Method implements some code
public interface IDemo{void DoSomethingUseful();void SomethingThatCanBeIgnored();}public class Demo : IDemo{public void DoSomethingUseful(){// no audit issuesConsole.WriteLine("Useful");}// audit issuespublic void SomethingThatCanBeIgnored(){}}
❌ Figure: Figure: Bad Example - No Comment within empty code block
public interface IDemo{void DoSomethingUseful();void SomethingThatCanBeIgnored();}public class Demo : IDemo{public void DoSomethingUseful(){// no audit issuesConsole.WriteLine("Useful");}// No audit issuespublic void SomethingThatCanBeIgnored(){// stub for IDemo interface}}
✅ Figure: Figure: Good Example - Added comment within Empty Code block method of interface class
Categories
Related rules
Need help?
SSW Consulting has over 30 years of experience developing awesome software solutions.