conventions & best practices
DESCRIPTION
Best Practices and Naming ConventionsTRANSCRIPT
![Page 1: Conventions & Best Practices](https://reader035.vdocuments.mx/reader035/viewer/2022062706/557ad6ffd8b42a85648b4658/html5/thumbnails/1.jpg)
Conventions & Best PracticesMelick Rajee Baranasooriya
http://melick-rajee.blogspot.com/
![Page 2: Conventions & Best Practices](https://reader035.vdocuments.mx/reader035/viewer/2022062706/557ad6ffd8b42a85648b4658/html5/thumbnails/2.jpg)
Naming Conventions
![Page 3: Conventions & Best Practices](https://reader035.vdocuments.mx/reader035/viewer/2022062706/557ad6ffd8b42a85648b4658/html5/thumbnails/3.jpg)
Declaring VariablesO Local Variables (Private, Static)
O Use Camel caseO First letter always simple O Use _ in frontO Capitalized the subsequent word
![Page 4: Conventions & Best Practices](https://reader035.vdocuments.mx/reader035/viewer/2022062706/557ad6ffd8b42a85648b4658/html5/thumbnails/4.jpg)
Declaring Variables ..O Local Variables (Others)
O Use Camel caseO First letter always simple O Never user _ (this is old)O Capitalized the subsequent word
![Page 5: Conventions & Best Practices](https://reader035.vdocuments.mx/reader035/viewer/2022062706/557ad6ffd8b42a85648b4658/html5/thumbnails/5.jpg)
Declaring Variables ..O Constants (public)
O Use Upper Camel caseO First letter always Capital
![Page 6: Conventions & Best Practices](https://reader035.vdocuments.mx/reader035/viewer/2022062706/557ad6ffd8b42a85648b4658/html5/thumbnails/6.jpg)
Declaring PropertiesO Use Pascal
O First letter always CapitalO Capitalized the subsequent wordO Use smart properties as much as
possible
![Page 7: Conventions & Best Practices](https://reader035.vdocuments.mx/reader035/viewer/2022062706/557ad6ffd8b42a85648b4658/html5/thumbnails/7.jpg)
Class NamesO Always use singular form
O Ex :- School , Person , SQLControllerO First Letter Capital
![Page 8: Conventions & Best Practices](https://reader035.vdocuments.mx/reader035/viewer/2022062706/557ad6ffd8b42a85648b4658/html5/thumbnails/8.jpg)
SummaryUpper CAMEL lower CAMEL _lower CAMEL
Types & Name Spaces
Local variables Static Fields (private)
Interfaces(ISchool)
Local constants Fields (private)
Methods , Properties , Events
Parameters
Fields (not private)
Constance
Static ReadOnly
Enum
![Page 9: Conventions & Best Practices](https://reader035.vdocuments.mx/reader035/viewer/2022062706/557ad6ffd8b42a85648b4658/html5/thumbnails/9.jpg)
Best Practices
![Page 10: Conventions & Best Practices](https://reader035.vdocuments.mx/reader035/viewer/2022062706/557ad6ffd8b42a85648b4658/html5/thumbnails/10.jpg)
Value Types Vs. Reference Types
O Value types more efficient than the reference.
O Use value types as possible
![Page 11: Conventions & Best Practices](https://reader035.vdocuments.mx/reader035/viewer/2022062706/557ad6ffd8b42a85648b4658/html5/thumbnails/11.jpg)
Use Properties instead of Public Variables
O Properties wrap the variables that allows encapsulation.O Can change @ once
![Page 12: Conventions & Best Practices](https://reader035.vdocuments.mx/reader035/viewer/2022062706/557ad6ffd8b42a85648b4658/html5/thumbnails/12.jpg)
Boxing Vs. UnboxingO Avoid Boxing (drain performance)
O Avoid Unboxing (drain performance)
![Page 13: Conventions & Best Practices](https://reader035.vdocuments.mx/reader035/viewer/2022062706/557ad6ffd8b42a85648b4658/html5/thumbnails/13.jpg)
Use is and as O Avoid Exceptions and handle null
![Page 14: Conventions & Best Practices](https://reader035.vdocuments.mx/reader035/viewer/2022062706/557ad6ffd8b42a85648b4658/html5/thumbnails/14.jpg)
String.Fortmat() or StringBuilder
![Page 15: Conventions & Best Practices](https://reader035.vdocuments.mx/reader035/viewer/2022062706/557ad6ffd8b42a85648b4658/html5/thumbnails/15.jpg)
Use Conditional Attributes
![Page 16: Conventions & Best Practices](https://reader035.vdocuments.mx/reader035/viewer/2022062706/557ad6ffd8b42a85648b4658/html5/thumbnails/16.jpg)
For each Vs. For O Foreach generate best execution
path
O Use count or length in the iterationO For ( .. ; .. ; Lengh)O For ( .. ; .. ; Count)
![Page 17: Conventions & Best Practices](https://reader035.vdocuments.mx/reader035/viewer/2022062706/557ad6ffd8b42a85648b4658/html5/thumbnails/17.jpg)
Try Catch O 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
![Page 18: Conventions & Best Practices](https://reader035.vdocuments.mx/reader035/viewer/2022062706/557ad6ffd8b42a85648b4658/html5/thumbnails/18.jpg)
Method and FunctionsO Don’t use too many parameters
O (not more than 4 or 5)O Use struct/Class or params
O Restrict to 15,20 linesO Can change the logic easily
![Page 19: Conventions & Best Practices](https://reader035.vdocuments.mx/reader035/viewer/2022062706/557ad6ffd8b42a85648b4658/html5/thumbnails/19.jpg)
Than you.