SlideShare a Scribd company logo
Software Development Best Practices
----
Coding Standards & Maintainable Code
Ankur Goyal
Email: ankur.fbd@gmail.com
for(j=0; j<array_len; j+ =8)
{
total += array[j+0 ];
total += array[j+1 ];
total += array[j+2 ]; /* Main body of
total += array[j+3]; * loop is unrolled
total += array[j+4]; * for greater speed.
total += array[j+5]; */
total += array[j+6 ];
total += array[j+7 ];
}
Warm up
for(j=0; j<array_len; j+ =8)
{
total += array[j+0 ];
total += array[j+1 ];
total += array[j+2 ];
/*
Main body of loop is unrolled for greater speed
total += array[j+3];
total += array[j+4];
total += array[j+5];
*/
total += array[j+6 ];
total += array[j+7 ];
}
Isn’t it better ?
What is it you expect, to get out of this Session?
Participant’s Expectations
Setting Expectations Right
• What this session is about?
– Identify & appreciate the importance of Coding
Standards
– Few examples
– Introduction to standard supporting tools
• What this session is not about?
– Coding Tutorial
– Details on coding standards
Maintainability
• Maintainability is the ease with which a product
can be modified in order to:
– correct defects or their cause
– meet new requirements
– cope with a changed environment
– e.g. iOS 5 to iOS 6, windows 7 to windows 8
Write simple, self-documenting code that is pleasant to revisit
even after months.
Coding Standards
• Coding standards are guidelines for code style
and documentation.
• The purpose is that any developer familiar with
the guidelines can work on any code that
followed them.
• We need to write code that minimizes the time it
would take someone else to understand it ---
even if that someone else is you.
Why Have Coding Standards?
• Reducing the cost of
software maintenance is the
most often cited reason for
following coding standards.
• ~80% of the lifetime cost of
a piece of software goes to
maintenance.
Is this really necessary ?
• YES. To all programmers, even if there is only one
developer on the project.
• Because:
– Most of the time software is not maintained by
the original author.
– If everyone follows the standards, you feel
comfortable using your colleague's code,
because it seems like your own code.
hmmm really ?
– Estimations are approved considering an average
programmer who follows coding standards.
– Not following coding standards will lead to review
comments & thereby rework, which in turn will lead to
effort variation.
– Since most of the time client delivery dates are fixed
hence it all leads to extra hours spent in office -> more
time -> more money.
– It’s a vicious circle, only way out is following coding
standards.
FEW
EXAMPLES
Using constants on LHS
• Constants should always be used on left hand
side of equality operator
• Avoids invalid assignment
• Avoids null pointer exceptions
Using constants on LHS
T h i s c o d e c a n c a u s e
N u l l P o i n t e r E x c e p t i o n
i f p a s s e d a r g u m e n t
‘ i n p u t ’ i s n u l l
R i g h t A p p r o a c h
Indentation
• Gives an indication of scope though doesn’t
affect program
• Must for maintainability & readability of code
Example
Compare
- Easier to Read
- Easier to Understand
- Easier to maintain
To
Pressing “Ctrl+shift+f” in eclipse formats source file
(set up your formatting style in Window|preferences | java | code style | formatter)
Commenting Code
• Document WHY & WHAT along with HOW.
• Comments should
- Clearly demonstrate the function of the code,
both to yourself and to other developers
• Comments should NOT be
- Too long
- Overcomplicated
Example
Compare
Example
To
 Comments are not about how much you write
 Comments should add illustration to the code for maintainability
Naming Variables
• Variable names are often thought to be less
important but they are vital to understanding
certain pieces of code.
• In the majority of programming languages,
variables can be assigned almost any name.
Example
Compare following:
To:
Trade off is generally between meaningfulness & shortness, rule of thumb is, always give
priority to meaningfulness.
Instance Creation
• Do not create instances as far as possible.
• creation of new instance is avoided in the
internal part of loop.
Example
Compare
Instance creation in loop, this may lead
to out of memory error…
To
Instance Creation
• Use valueOf() instead of new().
• valueOf() provides value from cache while
new() creates new instance.
Example
use
instead of
Cast
• As much as possible cast must be enclosed in
condition statement of instanceof.
Use instanceof()
This may lead to classcastexception
Use instanceof to avoid
classcastexception
Unreadable Code
• Write a code that can be understood by any
average programmer.
• This helps in maintainability & readability of
code.
• Helpful in understanding time critical projects
Example
Compare
To
Programmer’s expertise is not in writing complex code, expertise
is to write a code which is easy to understand & maintain.
String Concatenation
• Use StringBuffer and StringBuilder for String
concatenation operations.
• String is immutable hence creates new objects
whenever the value is changed
• Use StringBuffer if application is multithreaded &
synchronization is required
• Use StringBuilder elsewhere.
Example
Instead of
Use
Or
String object is
immutable whereas
StringBuffer/
StringBuilder
objects are mutable
REPOSITORY COMMENTS
• Often it is observed that repository comments do
not get the attention they deserve.
• Repository comments should convey the changes
committed along with applicable references e.g
– If bug is fixed mention fixed bug ID
– If any CR is implemented mention CR number/name
– If review comments are fixed mention review plan id
Example
Following are some of the real svn repo comments:
SVN repo comments serve purpose of maintaining code revision history, pay
respect to this fact & spend some time to write useful comments
Coding Standard & Best Practices
Tools
• CheckStyle
– makes sure that everyone in the team write code in a
similar manner
– is the glue that enables people to work together and to
free up their creativity instead of spending time and
energy at understanding inconsistent code.
• PMD
– reminds you of bad practices such as:
• Catching an exception without doing anything
• Suboptimal code - wasteful String/StringBuffer usage
• Duplicate code - copied/pasted code means copied/pasted bugs
Recap
• The purpose is that any developer familiar with the
guidelines can work on any code that followed them.
• Following coding standards saves both time and
money.
• Standardize early - the effort to bring your old work
into the standard will be too great otherwise.
• Document every time you violate a standard.
• Industry Standards > organizational standards >
project standards > no standards.
THANKS !!!
 Guidelines & practices mentioned in this slide were just a
tip of iceberg, there is no hard & fast rule regarding
guideline & they generally differ on basis of domain,
technology used & clients’ requirement etc.
Purpose of this presentation was to encourage habit of
following standards by identifying importance of the same.
Finally, following guidelines & adhering to standards is
responsibility of each individual.
Conclusion

More Related Content

What's hot

Code review
Code reviewCode review
Code review
Abhishek Sur
 
C# conventions & good practices
C# conventions & good practicesC# conventions & good practices
C# conventions & good practices
Tan Tran
 
Coding standards for java
Coding standards for javaCoding standards for java
Coding standards for javamaheshm1206
 
Refactoring Tips by Martin Fowler
Refactoring Tips by Martin FowlerRefactoring Tips by Martin Fowler
Refactoring Tips by Martin Fowler
Igor Crvenov
 
TDD - Test Driven Development
TDD - Test Driven DevelopmentTDD - Test Driven Development
TDD - Test Driven Development
Tung Nguyen Thanh
 
Clean code
Clean code Clean code
Clean code
Achintya Kumar
 
.Net platform .Net core fundamentals
.Net platform .Net core  fundamentals.Net platform .Net core  fundamentals
.Net platform .Net core fundamentals
Hosein Mansouri
 
Clean code
Clean codeClean code
Clean code
Jean Carlo Machado
 
Clean code and Code Smells
Clean code and Code SmellsClean code and Code Smells
Clean code and Code Smells
Mario Sangiorgio
 
Principles of Software testing
Principles of Software testingPrinciples of Software testing
Principles of Software testing
Md Mamunur Rashid
 
Code smell overview
Code smell overviewCode smell overview
Code smell overview
Pham Manh Lan
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
Sachithra Gayan
 
Code Quality
Code QualityCode Quality
Code Quality
François Camus
 
Code coverage
Code coverageCode coverage
Code coverage
Return on Intelligence
 
Importance of the quality of code
Importance of the quality of codeImportance of the quality of code
Importance of the quality of code
Shwe Yee
 
Commenting Best Practices
Commenting Best PracticesCommenting Best Practices
Commenting Best Practices
mh_azad
 
Clean code presentation
Clean code presentationClean code presentation
Clean code presentation
Bhavin Gandhi
 
TDD - Agile
TDD - Agile TDD - Agile
TDD - Agile
harinderpisces
 
Postman Collection Format v2.0 (pre-draft)
Postman Collection Format v2.0 (pre-draft)Postman Collection Format v2.0 (pre-draft)
Postman Collection Format v2.0 (pre-draft)
Postman
 
Unit Testing Concepts and Best Practices
Unit Testing Concepts and Best PracticesUnit Testing Concepts and Best Practices
Unit Testing Concepts and Best Practices
Derek Smith
 

What's hot (20)

Code review
Code reviewCode review
Code review
 
C# conventions & good practices
C# conventions & good practicesC# conventions & good practices
C# conventions & good practices
 
Coding standards for java
Coding standards for javaCoding standards for java
Coding standards for java
 
Refactoring Tips by Martin Fowler
Refactoring Tips by Martin FowlerRefactoring Tips by Martin Fowler
Refactoring Tips by Martin Fowler
 
TDD - Test Driven Development
TDD - Test Driven DevelopmentTDD - Test Driven Development
TDD - Test Driven Development
 
Clean code
Clean code Clean code
Clean code
 
.Net platform .Net core fundamentals
.Net platform .Net core  fundamentals.Net platform .Net core  fundamentals
.Net platform .Net core fundamentals
 
Clean code
Clean codeClean code
Clean code
 
Clean code and Code Smells
Clean code and Code SmellsClean code and Code Smells
Clean code and Code Smells
 
Principles of Software testing
Principles of Software testingPrinciples of Software testing
Principles of Software testing
 
Code smell overview
Code smell overviewCode smell overview
Code smell overview
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Code Quality
Code QualityCode Quality
Code Quality
 
Code coverage
Code coverageCode coverage
Code coverage
 
Importance of the quality of code
Importance of the quality of codeImportance of the quality of code
Importance of the quality of code
 
Commenting Best Practices
Commenting Best PracticesCommenting Best Practices
Commenting Best Practices
 
Clean code presentation
Clean code presentationClean code presentation
Clean code presentation
 
TDD - Agile
TDD - Agile TDD - Agile
TDD - Agile
 
Postman Collection Format v2.0 (pre-draft)
Postman Collection Format v2.0 (pre-draft)Postman Collection Format v2.0 (pre-draft)
Postman Collection Format v2.0 (pre-draft)
 
Unit Testing Concepts and Best Practices
Unit Testing Concepts and Best PracticesUnit Testing Concepts and Best Practices
Unit Testing Concepts and Best Practices
 

Similar to Software development best practices & coding guidelines

CPP03 - Repetition
CPP03 - RepetitionCPP03 - Repetition
CPP03 - Repetition
Michael Heron
 
Design Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best PracticesDesign Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best Practices
Inductive Automation
 
Design Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best PracticesDesign Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best Practices
Inductive Automation
 
The View - Lotusscript coding best practices
The View - Lotusscript coding best practicesThe View - Lotusscript coding best practices
The View - Lotusscript coding best practicesBill Buchan
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
Aiman Hud
 
PHP Code Quality
PHP Code QualityPHP Code Quality
PHP Code Quality
Usman Zafar
 
sCode optimization
sCode optimizationsCode optimization
sCode optimization
Satyamevjayte Haxor
 
Topic production code
Topic production codeTopic production code
Topic production code
Kavi Kumar
 
Software coding &amp; testing, software engineering
Software coding &amp; testing, software engineeringSoftware coding &amp; testing, software engineering
Software coding &amp; testing, software engineering
Rupesh Vaishnav
 
Cypress Best Pratices for Test Automation
Cypress Best Pratices for Test AutomationCypress Best Pratices for Test Automation
Cypress Best Pratices for Test Automation
Knoldus Inc.
 
Putting Compilers to Work
Putting Compilers to WorkPutting Compilers to Work
Putting Compilers to Work
SingleStore
 
代码大全(内训)
代码大全(内训)代码大全(内训)
代码大全(内训)
Horky Chen
 
Autotools, Design Patterns and more
Autotools, Design Patterns and moreAutotools, Design Patterns and more
Autotools, Design Patterns and more
Vicente Bolea
 
Improving Code Quality Through Effective Review Process
Improving Code Quality Through Effective  Review ProcessImproving Code Quality Through Effective  Review Process
Improving Code Quality Through Effective Review Process
Dr. Syed Hassan Amin
 
An Introduction To Software Development - Implementation
An Introduction To Software Development - ImplementationAn Introduction To Software Development - Implementation
An Introduction To Software Development - Implementation
Blue Elephant Consulting
 
Introduction to C ++.pptx
Introduction to C ++.pptxIntroduction to C ++.pptx
Introduction to C ++.pptx
VAIBHAVKADAGANCHI
 
Dev buchan 30 proven tips
Dev buchan 30 proven tipsDev buchan 30 proven tips
Dev buchan 30 proven tipsBill Buchan
 
Indy meetup#7 effective unit-testing-mule
Indy meetup#7 effective unit-testing-muleIndy meetup#7 effective unit-testing-mule
Indy meetup#7 effective unit-testing-mule
ikram_ahamed
 
[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...
[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...
[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...
DevDay.org
 
Coding
CodingCoding
Coding
Vishal Singh
 

Similar to Software development best practices & coding guidelines (20)

CPP03 - Repetition
CPP03 - RepetitionCPP03 - Repetition
CPP03 - Repetition
 
Design Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best PracticesDesign Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best Practices
 
Design Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best PracticesDesign Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best Practices
 
The View - Lotusscript coding best practices
The View - Lotusscript coding best practicesThe View - Lotusscript coding best practices
The View - Lotusscript coding best practices
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
 
PHP Code Quality
PHP Code QualityPHP Code Quality
PHP Code Quality
 
sCode optimization
sCode optimizationsCode optimization
sCode optimization
 
Topic production code
Topic production codeTopic production code
Topic production code
 
Software coding &amp; testing, software engineering
Software coding &amp; testing, software engineeringSoftware coding &amp; testing, software engineering
Software coding &amp; testing, software engineering
 
Cypress Best Pratices for Test Automation
Cypress Best Pratices for Test AutomationCypress Best Pratices for Test Automation
Cypress Best Pratices for Test Automation
 
Putting Compilers to Work
Putting Compilers to WorkPutting Compilers to Work
Putting Compilers to Work
 
代码大全(内训)
代码大全(内训)代码大全(内训)
代码大全(内训)
 
Autotools, Design Patterns and more
Autotools, Design Patterns and moreAutotools, Design Patterns and more
Autotools, Design Patterns and more
 
Improving Code Quality Through Effective Review Process
Improving Code Quality Through Effective  Review ProcessImproving Code Quality Through Effective  Review Process
Improving Code Quality Through Effective Review Process
 
An Introduction To Software Development - Implementation
An Introduction To Software Development - ImplementationAn Introduction To Software Development - Implementation
An Introduction To Software Development - Implementation
 
Introduction to C ++.pptx
Introduction to C ++.pptxIntroduction to C ++.pptx
Introduction to C ++.pptx
 
Dev buchan 30 proven tips
Dev buchan 30 proven tipsDev buchan 30 proven tips
Dev buchan 30 proven tips
 
Indy meetup#7 effective unit-testing-mule
Indy meetup#7 effective unit-testing-muleIndy meetup#7 effective unit-testing-mule
Indy meetup#7 effective unit-testing-mule
 
[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...
[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...
[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...
 
Coding
CodingCoding
Coding
 

Recently uploaded

Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
Tendenci - The Open Source AMS (Association Management Software)
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
Ortus Solutions, Corp
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
WSO2
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
vrstrong314
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Shahin Sheidaei
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
Philip Schwarz
 
RISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent EnterpriseRISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent Enterprise
Srikant77
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Mind IT Systems
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
Tier1 app
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
AMB-Review
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
Cyanic lab
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
wottaspaceseo
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
Ortus Solutions, Corp
 
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdfEnhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Jay Das
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns
 

Recently uploaded (20)

Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
 
RISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent EnterpriseRISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent Enterprise
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdfEnhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 

Software development best practices & coding guidelines

  • 1. Software Development Best Practices ---- Coding Standards & Maintainable Code Ankur Goyal Email: ankur.fbd@gmail.com
  • 2. for(j=0; j<array_len; j+ =8) { total += array[j+0 ]; total += array[j+1 ]; total += array[j+2 ]; /* Main body of total += array[j+3]; * loop is unrolled total += array[j+4]; * for greater speed. total += array[j+5]; */ total += array[j+6 ]; total += array[j+7 ]; } Warm up
  • 3. for(j=0; j<array_len; j+ =8) { total += array[j+0 ]; total += array[j+1 ]; total += array[j+2 ]; /* Main body of loop is unrolled for greater speed total += array[j+3]; total += array[j+4]; total += array[j+5]; */ total += array[j+6 ]; total += array[j+7 ]; } Isn’t it better ?
  • 4. What is it you expect, to get out of this Session? Participant’s Expectations
  • 5. Setting Expectations Right • What this session is about? – Identify & appreciate the importance of Coding Standards – Few examples – Introduction to standard supporting tools • What this session is not about? – Coding Tutorial – Details on coding standards
  • 6. Maintainability • Maintainability is the ease with which a product can be modified in order to: – correct defects or their cause – meet new requirements – cope with a changed environment – e.g. iOS 5 to iOS 6, windows 7 to windows 8 Write simple, self-documenting code that is pleasant to revisit even after months.
  • 7. Coding Standards • Coding standards are guidelines for code style and documentation. • The purpose is that any developer familiar with the guidelines can work on any code that followed them. • We need to write code that minimizes the time it would take someone else to understand it --- even if that someone else is you.
  • 8. Why Have Coding Standards? • Reducing the cost of software maintenance is the most often cited reason for following coding standards. • ~80% of the lifetime cost of a piece of software goes to maintenance.
  • 9. Is this really necessary ? • YES. To all programmers, even if there is only one developer on the project. • Because: – Most of the time software is not maintained by the original author. – If everyone follows the standards, you feel comfortable using your colleague's code, because it seems like your own code.
  • 10. hmmm really ? – Estimations are approved considering an average programmer who follows coding standards. – Not following coding standards will lead to review comments & thereby rework, which in turn will lead to effort variation. – Since most of the time client delivery dates are fixed hence it all leads to extra hours spent in office -> more time -> more money. – It’s a vicious circle, only way out is following coding standards.
  • 12. Using constants on LHS • Constants should always be used on left hand side of equality operator • Avoids invalid assignment • Avoids null pointer exceptions
  • 13. Using constants on LHS T h i s c o d e c a n c a u s e N u l l P o i n t e r E x c e p t i o n i f p a s s e d a r g u m e n t ‘ i n p u t ’ i s n u l l R i g h t A p p r o a c h
  • 14. Indentation • Gives an indication of scope though doesn’t affect program • Must for maintainability & readability of code
  • 15. Example Compare - Easier to Read - Easier to Understand - Easier to maintain To Pressing “Ctrl+shift+f” in eclipse formats source file (set up your formatting style in Window|preferences | java | code style | formatter)
  • 16. Commenting Code • Document WHY & WHAT along with HOW. • Comments should - Clearly demonstrate the function of the code, both to yourself and to other developers • Comments should NOT be - Too long - Overcomplicated
  • 18. Example To  Comments are not about how much you write  Comments should add illustration to the code for maintainability
  • 19. Naming Variables • Variable names are often thought to be less important but they are vital to understanding certain pieces of code. • In the majority of programming languages, variables can be assigned almost any name.
  • 20. Example Compare following: To: Trade off is generally between meaningfulness & shortness, rule of thumb is, always give priority to meaningfulness.
  • 21. Instance Creation • Do not create instances as far as possible. • creation of new instance is avoided in the internal part of loop.
  • 22. Example Compare Instance creation in loop, this may lead to out of memory error… To
  • 23. Instance Creation • Use valueOf() instead of new(). • valueOf() provides value from cache while new() creates new instance.
  • 25. Cast • As much as possible cast must be enclosed in condition statement of instanceof. Use instanceof() This may lead to classcastexception Use instanceof to avoid classcastexception
  • 26. Unreadable Code • Write a code that can be understood by any average programmer. • This helps in maintainability & readability of code. • Helpful in understanding time critical projects
  • 27. Example Compare To Programmer’s expertise is not in writing complex code, expertise is to write a code which is easy to understand & maintain.
  • 28. String Concatenation • Use StringBuffer and StringBuilder for String concatenation operations. • String is immutable hence creates new objects whenever the value is changed • Use StringBuffer if application is multithreaded & synchronization is required • Use StringBuilder elsewhere.
  • 29. Example Instead of Use Or String object is immutable whereas StringBuffer/ StringBuilder objects are mutable
  • 30. REPOSITORY COMMENTS • Often it is observed that repository comments do not get the attention they deserve. • Repository comments should convey the changes committed along with applicable references e.g – If bug is fixed mention fixed bug ID – If any CR is implemented mention CR number/name – If review comments are fixed mention review plan id
  • 31. Example Following are some of the real svn repo comments: SVN repo comments serve purpose of maintaining code revision history, pay respect to this fact & spend some time to write useful comments
  • 32. Coding Standard & Best Practices Tools • CheckStyle – makes sure that everyone in the team write code in a similar manner – is the glue that enables people to work together and to free up their creativity instead of spending time and energy at understanding inconsistent code. • PMD – reminds you of bad practices such as: • Catching an exception without doing anything • Suboptimal code - wasteful String/StringBuffer usage • Duplicate code - copied/pasted code means copied/pasted bugs
  • 33. Recap • The purpose is that any developer familiar with the guidelines can work on any code that followed them. • Following coding standards saves both time and money. • Standardize early - the effort to bring your old work into the standard will be too great otherwise. • Document every time you violate a standard. • Industry Standards > organizational standards > project standards > no standards.
  • 34. THANKS !!!  Guidelines & practices mentioned in this slide were just a tip of iceberg, there is no hard & fast rule regarding guideline & they generally differ on basis of domain, technology used & clients’ requirement etc. Purpose of this presentation was to encourage habit of following standards by identifying importance of the same. Finally, following guidelines & adhering to standards is responsibility of each individual. Conclusion