Announcement

BEST PROGRAMMING PRACTICES

BEST PROGRAMMING PRACTICES


PART 1

BestProgrammingPracticesTechiners
Best Programming Practices


















Introduction

This post will discuss the naming conventions and guidelines that will help developers to have maintainable code keeping the consistency throughout. The post is divided into three parts first being the Naming Conventions followed by two others. Naming Conventions are as per the Microsoft Standards.


This post is an outcome of one of my friend Ameer Khan who presented the topic during developers training session. It was applauded by all with many comments. Thanks to his work.

Naming Conventions

Consistency is the key to maintainable code. This statement is most true for naming your projects, source files, and identifiers including Fields, Variables, Properties, Methods, Parameters, Classes, Interfaces, and Namespaces. Following are the general guidelines that a developer can follow:

  1. Always use Camel Case or Pascal Case names.
  2. Avoid ALL CAPS and all lowercase names. Single lowercase words or letters are acceptable.
  3. Do not create declarations of the same type (namespace, class, method, property, field, or parameter) and access modifier (protected, public, private, internal) that vary only by capitalization.
  4. Do not use names that begin with a numeric character.
  5. Do add numeric suffixes to identifier names.
  6. Always choose meaningful and specific names.
  7. Always err on the side of verbosity not terseness.
  8. Variables and properties should describe and entity not the type of size.
  9. Do not use Hungarian Notation!
          Example: strName or iCount

     10. Avoid using abbreviations unless the full name is excessive.
     11. Avoid abbreviations longer than 5 character.
     12. Any abbreviation must be widely known and accepted.
     13. Use uppercase for two-letter abbreviations, and Pascal Case for longer                  abbreviations.
     14. Do not use C# reserved words for names.
     15. Avoid naming conflicts with existing .NET Framework namespaces, or                  types.
     16. Avoid adding redundant or meaningless prefixes and suffixes to identifiers
           Example:

           // Bad!
           public enum colorsEnum {....}
           public class CVehicle {....}
           public struct RectangleStruct {....}
    
     17. Do not include the parent class name within a property name.
           Example: Customer.Name NOT Customer.CustomerName
     18. Try to prefix Boolean variables and properties with "Can", "Is", or "Has".
     19. Append computational qualifiers to variable names like Average, Count,                  Sum, Min, and Max  where appropriate.
     20. When defining a root namespace, use a Product, Company, or Developer              Name as the root. Example: LanceHunt


Conclusion

Hope you will find above guidelines useful. Do let us know in the comment box below if you come across some more/new guidelines. Please do not forget to share with your colleagues and friends because sharing is caring. Happy Programming!

No comments: