Conventions & Best Practices

1,861 views

Published on

Best Practices and Naming Conventions

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,861
On SlideShare
0
From Embeds
0
Number of Embeds
1,350
Actions
Shares
0
Downloads
7
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Conventions & Best Practices

  1. 1. Conventions & Best Practices Melick Rajee Baranasooriya http://melick-rajee.blogspot.com/
  2. 2. Naming Conventions
  3. 3. Declaring VariablesO Local Variables (Private, Static) O Use Camel case O First letter always simple O Use _ in front O Capitalized the subsequent word
  4. 4. Declaring Variables ..O Local Variables (Others) O Use Camel case O First letter always simple O Never user _ (this is old) O Capitalized the subsequent word
  5. 5. Declaring Variables ..O Constants (public) O Use Upper Camel case O First letter always Capital
  6. 6. Declaring PropertiesO Use Pascal O First letter always Capital O Capitalized the subsequent word O Use smart properties as much as possible
  7. 7. Class NamesO Always use singular form O Ex :- School , Person , SQLControllerO First Letter Capital
  8. 8. SummaryUpper CAMEL lower CAMEL _lower CAMELTypes & Name Local variables Static FieldsSpaces (private)Interfaces Local constants Fields (private)(ISchool)Methods , ParametersProperties ,EventsFields (notprivate)ConstanceStatic ReadOnlyEnum
  9. 9. Best Practices
  10. 10. Value Types Vs. Reference TypesO Value types more efficient than the reference.O Use value types as possible
  11. 11. Use Properties instead of Public VariablesO Properties wrap the variables that allows encapsulation. O Can change @ once
  12. 12. Boxing Vs. UnboxingO Avoid Boxing (drain performance)O Avoid Unboxing (drain performance)
  13. 13. Use is and asO Avoid Exceptions and handle null
  14. 14. String.Fortmat() or StringBuilder
  15. 15. Use Conditional Attributes
  16. 16. For each Vs. ForO Foreach generate best execution pathO Use count or length in the iteration O For ( .. ; .. ; Lengh) O For ( .. ; .. ; Count)
  17. 17. Try CatchO Use try catch in the presentation layer O (handle it in a one place)O Don’t use many try catch in a single code block (use with care)O Use if you can handle
  18. 18. Method and FunctionsO Don’t use too many parameters O (not more than 4 or 5) O Use struct/Class or paramsO Restrict to 15,20 lines O Can change the logic easily
  19. 19. Than you.

×