• The primary goal of C# coding standards and principles is to help programmers improve their craft by writing code that is more performant and easier to maintain.
  • We’ll look at some examples of good code versus examples of bad code.
  • This will set the stage for a discussion of why we need coding standards, principles, and methodologies.
  • We’ll talk about naming, commenting, and formatting conventions for source code, including classes, methods, and variables.
  • A large program can be difficult to grasp and maintain.
  • Learning the code and what it does can be a huge challenge for junior programmers.
  • Working on such projects can be challenging for teams.
  • And it can make testing difficult.
  • As a result, we will look at how you can use modularity to break down programs into smaller modules that all work together to produce a fully functional solution that is also fully testable and can be worked on by multiple teams.
  • At the same time, it is much easier to read, understand, and document.

    The objective of Coding Standards and Principles

  • Learn why bad code has a negative impact on projects.
  • Understand how good code benefits projects.
  • Learn how coding standards help to improve code and how to enforce them.
  • Learn how coding principles improve software quality.
  • Learn how methodologies can help you write clean code.
  • Implement coding guidelines.
  • Choose solutions that make the fewest assumptions.
  • SOLID code is written with minimal code duplication.

    Good code versus bad code

    S.No Good Code Bad Code
    1 Proper indentation. Improper indentation.
    2 Meaningful comments. Comments that state the obvious.
    3 API documentation comments. Comments that excuse bad code.
    4 Commented out lines of code.
    5 A proper organization using namespaces. An improper organization using namespaces.
    6 Good naming conventions. Bad naming conventions.
    7 Classes that do one job. Classes that do multiple jobs.
    8 Methods that do one thing. Methods that do many things.
    9 Methods with less than 10 lines, and preferably no more than 4. Methods with more than 10 lines of code.
    10 Methods with no more than two parameters. Methods with more than two parameters.
    11 Proper use of exceptions. Using exceptions to control program flow.
    12 Code that is readable. Code that is difficult to read.
    13 Code that is loosely coupled. Code that is tightly coupled.
    14 High cohesion. Low cohesion.
    15 Objects are cleanly disposed of. Objects left hanging around.
    16 Avoidance of the Finalize() method. Use of the Finalize() method.
    17 The right level of abstraction. Over-engineering.
    18 Use of regions in large classes.  Lack of regions in large classes.
    19 Encapsulation and information hiding.  Directly exposing information.
    20 Object-oriented code. Spaghetti code.
    21 Design patterns. Design anti-patterns.

 

(Detailed Explanation of Bad Code will be discussed in the next post….Stay Tuned…..)