2865-1675169569670-U11 - 3.2 Best Practice For Coding

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 15

Best practice for coding

Slide No : 3.2
Content
• Why is best coding practices being important
• Name things well
• Indentation and spacing
• Avoid writing very long methods
• Method name should tell what it does.
• A method should do only one job
• Comments
•Why is best coding practices being
important

• To develop reliable and maintainable applications, you


must follow best coding practices.
• Benefits of using good practices
• Improve Workflow
• Reduce Cost
• Less risks, More security
Name things well
• Names are everywhere in software. We name variables, methods,
classes, functions, source files etc..
• Naming Conventions
• Examples –
• Camel case
• Pascal case
Camel case
• The first character of all words, except the first word, is upper
case and other characters are lower case.
• Example:-
• helloWorld
Pascal case
• First character of all word is in upper case and other characters are in
lower case.
Example: HelloWorld
Indentation and spacing
• 1. Use Tab for indentation. Do not use SPACES.
• Comments should be in the same level as the code
A class should not be connected with too
many other classes.
Methods

• Should be very small (20-30 lines max, not more than 1 screen)
• Use Descriptive names
• Do one thing
Avoid writing very long methods

• A method should typically have 1-50 lines of code. If a method has


more than 50 lines of cod, you must consider re factoring into
separate methods.
Method name should tell what it does.
• Good
Void SavePhoneNumber (string PhoneNumber)
{
// Save the phone number.
}
• Not Good
// This method will save the phone number.
Void SaveDetails (string PhoneNumber)
{
// Save the phone number.
}
A method should do only one job
• A method should do only ‘one job’. Do not combine more than one
job in a single method, even if those jobs are very small.
• Good
• Not Good
Comments
Good and meaningful comments make code more
maintainable. However,
Do not write comments for every line code and every
variable declared.
Use // or /// for comments. Avoid using /*…*/ or
“flowerbox ” comment blocks
Thank You!

You might also like