Conventions & Best Practices

Preview:

DESCRIPTION

Best Practices and Naming Conventions

Citation preview

Conventions & Best PracticesMelick Rajee Baranasooriya

http://melick-rajee.blogspot.com/

Naming Conventions

Declaring VariablesO Local Variables (Private, Static)

O Use Camel caseO First letter always simple O Use _ in frontO Capitalized the subsequent word

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

Declaring Variables ..O Constants (public)

O Use Upper Camel caseO First letter always Capital

Declaring PropertiesO Use Pascal

O First letter always CapitalO Capitalized the subsequent wordO Use smart properties as much as

possible

Class NamesO Always use singular form

O Ex :- School , Person , SQLControllerO First Letter Capital

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

Best Practices

Value Types Vs. Reference Types

O Value types more efficient than the reference.

O Use value types as possible

Use Properties instead of Public Variables

O Properties wrap the variables that allows encapsulation.O Can change @ once

Boxing Vs. UnboxingO Avoid Boxing (drain performance)

O Avoid Unboxing (drain performance)

Use is and as O Avoid Exceptions and handle null

String.Fortmat() or StringBuilder

Use Conditional Attributes

For each Vs. For O Foreach generate best execution

path

O Use count or length in the iterationO For ( .. ; .. ; Lengh)O For ( .. ; .. ; Count)

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

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

Than you.

Recommended