SlideShare a Scribd company logo
Coding
Conventions
Overview of coding conventions.
By THITIPONG JAMPAJEEN
What are Coding conventions?
Coding conventions are a set of guidelines for a specific programming
language or recommend programming style.
These conventions usually cover file organization, indentation, comments,
declarations, statements, white space, naming conventions, programming
practices, programming principles,programming rules of thumb,
architectural best practices, etc.
What are Coding conventions?
Code conventions are important to programmers for a number of
reasons:
● 40%-80% of the lifetime cost of a piece of software goes to maintenance.
● Hardly any software is maintained for its whole life by the original author.
● Code conventions improve the readability of the software, allowing
engineers to understand new code more quickly and thoroughly.
● If you ship your source code as a product, you need to make sure it is as
well packaged and clean as any other product you create
What are Coding conventions?
Software Engineering
Software engineering is the process by which the project is specified and
designed . It is absolutely fundamental to the success of projects ,
particularly if they are large projects . The software engineering process is
what runs the coding process to successful completion . Good software
engineering can make the difference between a successful project - both in
financial and engineering terms - and a project that is , at worst , dead on
delivery . Good software engineering will minimise downstream costs and
maximise the marketing success of the project .
What are Coding conventions?
Quality
Software peer review frequently involves reading source code. This type of
peer review is primarily a defect detection activity. By definition, only the
original author of a piece of code has read the source file before the code is
submitted for review. Code that is written using consistent guidelines is
easier for other reviewers to understand and assimilate, improving the
efficacy of the defect detection process.
Even for the original author, consistently coded software eases maintainability.
There is no guarantee that an individual will remember the precise rationale
for why a particular piece of code was written in a certain way long after the
code was originally written. Coding conventions can help. Consistent use of
whitespace improves readability and reduces the time it takes to understand
Common Conventions
Programming principles & rules of thumb
● Code smell
Duplicated code: identical or very similar code exists in more than one
location.
Long method: a method, function, or procedure that has grown too large.
Large class: a class that has grown too large. See God object.
Too many parameters: a long list of parameters in a procedure or
function make readability and code quality worse.
Common Conventions
Programming principles & rules of thumb (Cont.)
● Code smell
Feature envy: a class that uses methods of another class excessively.
Inappropriate intimacy: a class that has dependencies on
implementation details of another class.
Lazy class / Freeloader: a class that does too little.
Common Conventions
Programming principles & rules of thumb (Cont.)
● Code smell
Contrived complexity: forced usage of overly complicated design
patterns where simpler design would suffice.
Excessively long identifiers: in particular, the use of naming conventions
to provide disambiguation that should be implicit in the software
architecture.
Excessively short identifiers: the name of a variable should reflect its
function unless the function is obvious.
Common Conventions
Programming principles & rules of thumb (Cont.)
● Code smell
Excessive use of literals: these should be coded as named constants, to
improve readability and to avoid programming errors. Additionally, literals
can and should be externalized into resource files/scripts where possible,
to facilitate localization of software if it is intended to be deployed in
different regions.
Complex conditionals: branches that check lots of unrelated conditions
and edge cases that don't seem to capture the meaning of a block of code.
Common Conventions
Programming principles & rules of thumb (Cont.)
● Rule of three is a code refactoring rule of thumb to decide when a
replicated piece of code should be replaced by a new procedure. It states
that the code can be copied once, but that when the same code is used
three times, it should be extracted into a new procedure.
Common Conventions
Naming Conventions
Common Conventions
Comment conventions
Common Conventions
Indent style conventions
Best practice / examples?
Apache Cloudstack
Java Coding Conventions
These are mostly taken from the Java Programming Style Guidelines with
modifications to reflect current style in Cloudstack. That document is itself
derived from Sun’s original Java Code Conventions document.
Apache Cloudstack
Naming Conventions
● Names representing types must be nouns and written in mixed case
starting with upper case, e.g., StoragePool.
● Variable names must be in mixed case starting with lower case, e.g.,
virtualRouter.
● Names representing constants (final variables) must be all uppercase
using underscore to separate words: e.g. MAX_TEMPLATE_SIZE_MB
● Names representing methods must be verbs and written in mixed case
starting with lower case: e.g. copyTemplateToZone.
● Abbreviations and acronyms should not be uppercase when used as
name: e.g. startElbVm
Apache Cloudstack
Naming Conventions (Cont.)
● Private class variables should have underscore prefix: *e.g.,
_downloadTimer. Exception: Transfer Objects (TOs), Database objects
(VOs), Command objects:- private class variables in these classes have
no underscores. The exception is justified since these are usually logged
and are more readable without underscores.
● Static variables are prefixed with s_: e.g. s_logger
● The is prefix should be used for boolean variables and methods: e.g.
isFinished.
● Exception classes should be suffixed with Exception.
● Default interface implementations can be prefixed by Default or if intended
to be subclassed, suffixed by Base: e.g.:
Apache Cloudstack
Files, Layout and Whitespace
● File content must be kept within 120 columns.
● Continuation of lines should be obvious:
totalSum = a + b + c +
d + e;
● Must indent with spaces, not tabs. Indentation = 4 spaces in place of a tab.
● Line endings must be LR (Unix/Linux/Mac format)
● White Space Rules
o Operators should be surrounded by a space character.
o Java reserved words should be surrounded by a white space.
o Commas should be followed by a white space.
Apache Cloudstack
Files, Layout and Whitespace (Cont.)
● Block layout should be similar to the example here. Class, interface, and
method blocks should also use this layout:
while (!done) {
doSomething();
done = moreToDo();
}
● If-else clauses, try-catch must use the following layout:
if (condition) {
statements;
} else {
statements;
}
Apache Cloudstack
Statements
● Imported classes should always be listed explicitly. No wildcards. The list
of imports should be kept minimal and organized using your IDE
● Class and Interface declarations should be organized in the following
manner:
o Class/Interface documentation.
o class or interface statement.
o Class (static) variables in the order public, protected, package (no
access modifier), private.
o Instance variables in the order public, protected, package (no access
modifier), private.
o Constructors.
Apache Cloudstack
Statements (Cont.)
● Type conversions must always be done explicitly. Never rely on implicit
type conversion.
● Variables should be initialized where they are declared and they should be
declared in the smallest scope possible
● Class variables should never be declared public
● Loop variables should be initialized immediately before the loop.
● The conditional should be put on a separate line. This improves
debuggability when there is a failure.
● The use of magic numbers in the code should be avoided. Numbers other
than 0 and 1can be considered declared as named constants instead.
Apache Cloudstack
Comments
● Tricky code should not be commented but rewritten. Code should be self
documenting
● Code that parses special input strings (e.g, comma delimited) should
provide examples of valid strings in comments
● Use // for all non-JavaDoc comments, including multi-line comments
● Comments should be in English
● Comments should be indented relative to their position in the code
● All public classes and public and protected functions within public classes
should be documented using the Java documentation (javadoc)
conventions
Apache Cloudstack
Naming Conventions for Design Patterns
● If an interface has only a single implementation, the implementing class
has a suffix Impl
● A class that maps to a database table is known as a Value Object and is
suffixed with VO: e.g., NetworkVO. This actually maps to the EJB DTO
pattern rather than the EJB VO pattern.
● A class that transfers data from one tier to another (e.g., from the business
logic tier to the resource layer) is a Transfer Object and is suffixed withTO:
e.g., LoadBalancerTO.
● A utility class that encapsulates common utilities (e.g., conversion between
ip address formats) is suffixed with Utils: e.g., NetUtils. These classes
do not hold state. Generally all methods are static.
References.
Additional References:
● Java Programming Style Guidelines
● Java Code Conventions
● http://www.mongodb.org/about/contributors/kernel-code-style/
● https://code.google.com/p/google-styleguide/
● http://cloudstack.apache.org/develop/coding-conventions.html
● http://en.wikipedia.org/wiki/Code_refactoring
● http://en.wikipedia.org/wiki/Code_smell
● http://en.wikipedia.org/wiki/God_object

More Related Content

What's hot

Coding standard
Coding standardCoding standard
Coding standard
FAROOK Samath
 
Dart PPT.pptx
Dart PPT.pptxDart PPT.pptx
Dart PPT.pptx
DSCMESCOE
 
Java programming course for beginners
Java programming course for beginnersJava programming course for beginners
Java programming course for beginners
Eduonix Learning Solutions
 
python-ppt.ppt
python-ppt.pptpython-ppt.ppt
python-ppt.ppt
MohammadSamiuddin10
 
Intro to programming and how to start that career
Intro to programming and how to start that careerIntro to programming and how to start that career
Intro to programming and how to start that career
Tarek Alabd
 
Java interview questions
Java interview questionsJava interview questions
Java interview questions
G C Reddy Technologies
 
Coding standards PSR-1 & PSR-2
Coding standards PSR-1 & PSR-2Coding standards PSR-1 & PSR-2
Coding standards PSR-1 & PSR-2Aram Baghdasaryan
 
Statements and Conditions in PHP
Statements and Conditions in PHPStatements and Conditions in PHP
Statements and Conditions in PHP
Maruf Abdullah (Rion)
 
Java Presentation For Syntax
Java Presentation For SyntaxJava Presentation For Syntax
Java Presentation For Syntax
PravinYalameli
 
Comments in C Programming
Comments in C ProgrammingComments in C Programming
Comments in C Programming
programming9
 
Oops in java
Oops in javaOops in java
Exception Handling
Exception HandlingException Handling
Exception Handling
Reddhi Basu
 
Java data types, variables and jvm
Java data types, variables and jvm Java data types, variables and jvm
Java data types, variables and jvm
Madishetty Prathibha
 
TDD in C - Recently Used List Kata
TDD in C - Recently Used List KataTDD in C - Recently Used List Kata
TDD in C - Recently Used List Kata
Olve Maudal
 
Python
PythonPython
Django Tutorial | Django Web Development With Python | Django Training and Ce...
Django Tutorial | Django Web Development With Python | Django Training and Ce...Django Tutorial | Django Web Development With Python | Django Training and Ce...
Django Tutorial | Django Web Development With Python | Django Training and Ce...
Edureka!
 

What's hot (20)

Coding standard
Coding standardCoding standard
Coding standard
 
Best coding practices
Best coding practicesBest coding practices
Best coding practices
 
Dart PPT.pptx
Dart PPT.pptxDart PPT.pptx
Dart PPT.pptx
 
Java programming course for beginners
Java programming course for beginnersJava programming course for beginners
Java programming course for beginners
 
python-ppt.ppt
python-ppt.pptpython-ppt.ppt
python-ppt.ppt
 
Core java Essentials
Core java EssentialsCore java Essentials
Core java Essentials
 
Intro to programming and how to start that career
Intro to programming and how to start that careerIntro to programming and how to start that career
Intro to programming and how to start that career
 
Java interview questions
Java interview questionsJava interview questions
Java interview questions
 
Coding standards PSR-1 & PSR-2
Coding standards PSR-1 & PSR-2Coding standards PSR-1 & PSR-2
Coding standards PSR-1 & PSR-2
 
Statements and Conditions in PHP
Statements and Conditions in PHPStatements and Conditions in PHP
Statements and Conditions in PHP
 
Java Presentation For Syntax
Java Presentation For SyntaxJava Presentation For Syntax
Java Presentation For Syntax
 
Java programming-examples
Java programming-examplesJava programming-examples
Java programming-examples
 
Comments in C Programming
Comments in C ProgrammingComments in C Programming
Comments in C Programming
 
Oops in java
Oops in javaOops in java
Oops in java
 
Exception Handling
Exception HandlingException Handling
Exception Handling
 
C sharp
C sharpC sharp
C sharp
 
Java data types, variables and jvm
Java data types, variables and jvm Java data types, variables and jvm
Java data types, variables and jvm
 
TDD in C - Recently Used List Kata
TDD in C - Recently Used List KataTDD in C - Recently Used List Kata
TDD in C - Recently Used List Kata
 
Python
PythonPython
Python
 
Django Tutorial | Django Web Development With Python | Django Training and Ce...
Django Tutorial | Django Web Development With Python | Django Training and Ce...Django Tutorial | Django Web Development With Python | Django Training and Ce...
Django Tutorial | Django Web Development With Python | Django Training and Ce...
 

Viewers also liked

April 2016 Medical Coding Q&A Webinar
April 2016 Medical Coding Q&A WebinarApril 2016 Medical Coding Q&A Webinar
April 2016 Medical Coding Q&A Webinar
Laureen Jandroep
 
HCC Coding Infographic: Critical Element of Risk Management
HCC Coding Infographic: Critical Element of Risk ManagementHCC Coding Infographic: Critical Element of Risk Management
HCC Coding Infographic: Critical Element of Risk Management
PYA, P.C.
 
BIOKIMI KLINIKE ME HEMATOLOGJI
BIOKIMI KLINIKE ME HEMATOLOGJIBIOKIMI KLINIKE ME HEMATOLOGJI
BIOKIMI KLINIKE ME HEMATOLOGJI
The Pharmacist
 
Power point diabetes
Power point diabetesPower point diabetes
Power point diabeteslulutor90
 
Presentacion Diabetes
Presentacion DiabetesPresentacion Diabetes
Presentacion Diabetes
estrellaaviles
 
Diabetes powerpoint
Diabetes powerpointDiabetes powerpoint
Diabetes powerpointmldanforth
 

Viewers also liked (9)

April 2016 Medical Coding Q&A Webinar
April 2016 Medical Coding Q&A WebinarApril 2016 Medical Coding Q&A Webinar
April 2016 Medical Coding Q&A Webinar
 
HCC Coding Infographic: Critical Element of Risk Management
HCC Coding Infographic: Critical Element of Risk ManagementHCC Coding Infographic: Critical Element of Risk Management
HCC Coding Infographic: Critical Element of Risk Management
 
BIOKIMI KLINIKE ME HEMATOLOGJI
BIOKIMI KLINIKE ME HEMATOLOGJIBIOKIMI KLINIKE ME HEMATOLOGJI
BIOKIMI KLINIKE ME HEMATOLOGJI
 
Power point diabetes
Power point diabetesPower point diabetes
Power point diabetes
 
Diabetes
DiabetesDiabetes
Diabetes
 
Presentacion Diabetes
Presentacion DiabetesPresentacion Diabetes
Presentacion Diabetes
 
Diabetes mellitus
Diabetes mellitusDiabetes mellitus
Diabetes mellitus
 
Diabetes Mellitus
Diabetes MellitusDiabetes Mellitus
Diabetes Mellitus
 
Diabetes powerpoint
Diabetes powerpointDiabetes powerpoint
Diabetes powerpoint
 

Similar to Coding conventions

Coding standards
Coding standardsCoding standards
Coding standards
Mimoh Ojha
 
Coding
CodingCoding
Coding
Vishal Singh
 
Best practices in enterprise applications
Best practices in enterprise applicationsBest practices in enterprise applications
Best practices in enterprise applicationsChandra Sekhar Saripaka
 
GTU PHP Project Training Guidelines
GTU PHP Project Training GuidelinesGTU PHP Project Training Guidelines
GTU PHP Project Training Guidelines
TOPS Technologies
 
Codings Standards
Codings StandardsCodings Standards
Codings Standards
Philip Johnson
 
Why Drupal is Rockstar?
Why Drupal is Rockstar?Why Drupal is Rockstar?
Why Drupal is Rockstar?
Gerald Villorente
 
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
 
Software Craftmanship - Cours Polytech
Software Craftmanship - Cours PolytechSoftware Craftmanship - Cours Polytech
Software Craftmanship - Cours Polytech
yannick grenzinger
 
Google Objective-C Style Guide
Google Objective-C Style GuideGoogle Objective-C Style Guide
Google Objective-C Style Guide
Winston Hsieh
 
Google Objective-C Style Guide
Google Objective-C Style GuideGoogle Objective-C Style Guide
Google Objective-C Style Guide
Winston Hsieh
 
05 Lecture - PARALLEL Programming in C ++.pdf
05 Lecture - PARALLEL Programming in C ++.pdf05 Lecture - PARALLEL Programming in C ++.pdf
05 Lecture - PARALLEL Programming in C ++.pdf
alivaisi1
 
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
 
GTU Guidelines for Project on JAVA
GTU Guidelines for Project on JAVAGTU Guidelines for Project on JAVA
GTU Guidelines for Project on JAVA
TOPS Technologies
 
Porcorn tutorial
Porcorn tutorialPorcorn tutorial
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
 
9-Coding.ppt
9-Coding.ppt9-Coding.ppt
9-Coding.ppt
KomalSinghGill
 
Learn java theory presentation
Learn java theory presentationLearn java theory presentation
Learn java theory presentation
Mark John Lado, MIT
 

Similar to Coding conventions (20)

Coding standards
Coding standardsCoding standards
Coding standards
 
Coding
CodingCoding
Coding
 
Best practices in enterprise applications
Best practices in enterprise applicationsBest practices in enterprise applications
Best practices in enterprise applications
 
GTU PHP Project Training Guidelines
GTU PHP Project Training GuidelinesGTU PHP Project Training Guidelines
GTU PHP Project Training Guidelines
 
Abcxyz
AbcxyzAbcxyz
Abcxyz
 
Codings Standards
Codings StandardsCodings Standards
Codings Standards
 
Why Drupal is Rockstar?
Why Drupal is Rockstar?Why Drupal is Rockstar?
Why Drupal is Rockstar?
 
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
 
Software Craftmanship - Cours Polytech
Software Craftmanship - Cours PolytechSoftware Craftmanship - Cours Polytech
Software Craftmanship - Cours Polytech
 
Google Objective-C Style Guide
Google Objective-C Style GuideGoogle Objective-C Style Guide
Google Objective-C Style Guide
 
Google Objective-C Style Guide
Google Objective-C Style GuideGoogle Objective-C Style Guide
Google Objective-C Style Guide
 
05 Lecture - PARALLEL Programming in C ++.pdf
05 Lecture - PARALLEL Programming in C ++.pdf05 Lecture - PARALLEL Programming in C ++.pdf
05 Lecture - PARALLEL Programming in C ++.pdf
 
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
 
Dtacs
DtacsDtacs
Dtacs
 
GTU Guidelines for Project on JAVA
GTU Guidelines for Project on JAVAGTU Guidelines for Project on JAVA
GTU Guidelines for Project on JAVA
 
Porcorn tutorial
Porcorn tutorialPorcorn tutorial
Porcorn tutorial
 
Importance of the quality of code
Importance of the quality of codeImportance of the quality of code
Importance of the quality of code
 
9-Coding.ppt
9-Coding.ppt9-Coding.ppt
9-Coding.ppt
 
Learn java theory presentation
Learn java theory presentationLearn java theory presentation
Learn java theory presentation
 

Recently uploaded

Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
Juraj Vysvader
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
informapgpstrackings
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 
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
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
XfilesPro
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
takuyayamamoto1800
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
IES VE
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Globus
 
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
 
Designing for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web ServicesDesigning for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web Services
KrzysztofKkol1
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Anthony Dahanne
 
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
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
vrstrong314
 
Strategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptxStrategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptx
varshanayak241
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
abdulrafaychaudhry
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
WSO2
 

Recently uploaded (20)

Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
 
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
 
Designing for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web ServicesDesigning for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web Services
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
 
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
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
 
Strategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptxStrategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptx
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
 

Coding conventions

  • 1. Coding Conventions Overview of coding conventions. By THITIPONG JAMPAJEEN
  • 2. What are Coding conventions? Coding conventions are a set of guidelines for a specific programming language or recommend programming style. These conventions usually cover file organization, indentation, comments, declarations, statements, white space, naming conventions, programming practices, programming principles,programming rules of thumb, architectural best practices, etc.
  • 3. What are Coding conventions? Code conventions are important to programmers for a number of reasons: ● 40%-80% of the lifetime cost of a piece of software goes to maintenance. ● Hardly any software is maintained for its whole life by the original author. ● Code conventions improve the readability of the software, allowing engineers to understand new code more quickly and thoroughly. ● If you ship your source code as a product, you need to make sure it is as well packaged and clean as any other product you create
  • 4. What are Coding conventions? Software Engineering Software engineering is the process by which the project is specified and designed . It is absolutely fundamental to the success of projects , particularly if they are large projects . The software engineering process is what runs the coding process to successful completion . Good software engineering can make the difference between a successful project - both in financial and engineering terms - and a project that is , at worst , dead on delivery . Good software engineering will minimise downstream costs and maximise the marketing success of the project .
  • 5. What are Coding conventions? Quality Software peer review frequently involves reading source code. This type of peer review is primarily a defect detection activity. By definition, only the original author of a piece of code has read the source file before the code is submitted for review. Code that is written using consistent guidelines is easier for other reviewers to understand and assimilate, improving the efficacy of the defect detection process. Even for the original author, consistently coded software eases maintainability. There is no guarantee that an individual will remember the precise rationale for why a particular piece of code was written in a certain way long after the code was originally written. Coding conventions can help. Consistent use of whitespace improves readability and reduces the time it takes to understand
  • 6. Common Conventions Programming principles & rules of thumb ● Code smell Duplicated code: identical or very similar code exists in more than one location. Long method: a method, function, or procedure that has grown too large. Large class: a class that has grown too large. See God object. Too many parameters: a long list of parameters in a procedure or function make readability and code quality worse.
  • 7. Common Conventions Programming principles & rules of thumb (Cont.) ● Code smell Feature envy: a class that uses methods of another class excessively. Inappropriate intimacy: a class that has dependencies on implementation details of another class. Lazy class / Freeloader: a class that does too little.
  • 8. Common Conventions Programming principles & rules of thumb (Cont.) ● Code smell Contrived complexity: forced usage of overly complicated design patterns where simpler design would suffice. Excessively long identifiers: in particular, the use of naming conventions to provide disambiguation that should be implicit in the software architecture. Excessively short identifiers: the name of a variable should reflect its function unless the function is obvious.
  • 9. Common Conventions Programming principles & rules of thumb (Cont.) ● Code smell Excessive use of literals: these should be coded as named constants, to improve readability and to avoid programming errors. Additionally, literals can and should be externalized into resource files/scripts where possible, to facilitate localization of software if it is intended to be deployed in different regions. Complex conditionals: branches that check lots of unrelated conditions and edge cases that don't seem to capture the meaning of a block of code.
  • 10. Common Conventions Programming principles & rules of thumb (Cont.) ● Rule of three is a code refactoring rule of thumb to decide when a replicated piece of code should be replaced by a new procedure. It states that the code can be copied once, but that when the same code is used three times, it should be extracted into a new procedure.
  • 14. Best practice / examples?
  • 15. Apache Cloudstack Java Coding Conventions These are mostly taken from the Java Programming Style Guidelines with modifications to reflect current style in Cloudstack. That document is itself derived from Sun’s original Java Code Conventions document.
  • 16. Apache Cloudstack Naming Conventions ● Names representing types must be nouns and written in mixed case starting with upper case, e.g., StoragePool. ● Variable names must be in mixed case starting with lower case, e.g., virtualRouter. ● Names representing constants (final variables) must be all uppercase using underscore to separate words: e.g. MAX_TEMPLATE_SIZE_MB ● Names representing methods must be verbs and written in mixed case starting with lower case: e.g. copyTemplateToZone. ● Abbreviations and acronyms should not be uppercase when used as name: e.g. startElbVm
  • 17. Apache Cloudstack Naming Conventions (Cont.) ● Private class variables should have underscore prefix: *e.g., _downloadTimer. Exception: Transfer Objects (TOs), Database objects (VOs), Command objects:- private class variables in these classes have no underscores. The exception is justified since these are usually logged and are more readable without underscores. ● Static variables are prefixed with s_: e.g. s_logger ● The is prefix should be used for boolean variables and methods: e.g. isFinished. ● Exception classes should be suffixed with Exception. ● Default interface implementations can be prefixed by Default or if intended to be subclassed, suffixed by Base: e.g.:
  • 18. Apache Cloudstack Files, Layout and Whitespace ● File content must be kept within 120 columns. ● Continuation of lines should be obvious: totalSum = a + b + c + d + e; ● Must indent with spaces, not tabs. Indentation = 4 spaces in place of a tab. ● Line endings must be LR (Unix/Linux/Mac format) ● White Space Rules o Operators should be surrounded by a space character. o Java reserved words should be surrounded by a white space. o Commas should be followed by a white space.
  • 19. Apache Cloudstack Files, Layout and Whitespace (Cont.) ● Block layout should be similar to the example here. Class, interface, and method blocks should also use this layout: while (!done) { doSomething(); done = moreToDo(); } ● If-else clauses, try-catch must use the following layout: if (condition) { statements; } else { statements; }
  • 20. Apache Cloudstack Statements ● Imported classes should always be listed explicitly. No wildcards. The list of imports should be kept minimal and organized using your IDE ● Class and Interface declarations should be organized in the following manner: o Class/Interface documentation. o class or interface statement. o Class (static) variables in the order public, protected, package (no access modifier), private. o Instance variables in the order public, protected, package (no access modifier), private. o Constructors.
  • 21. Apache Cloudstack Statements (Cont.) ● Type conversions must always be done explicitly. Never rely on implicit type conversion. ● Variables should be initialized where they are declared and they should be declared in the smallest scope possible ● Class variables should never be declared public ● Loop variables should be initialized immediately before the loop. ● The conditional should be put on a separate line. This improves debuggability when there is a failure. ● The use of magic numbers in the code should be avoided. Numbers other than 0 and 1can be considered declared as named constants instead.
  • 22. Apache Cloudstack Comments ● Tricky code should not be commented but rewritten. Code should be self documenting ● Code that parses special input strings (e.g, comma delimited) should provide examples of valid strings in comments ● Use // for all non-JavaDoc comments, including multi-line comments ● Comments should be in English ● Comments should be indented relative to their position in the code ● All public classes and public and protected functions within public classes should be documented using the Java documentation (javadoc) conventions
  • 23. Apache Cloudstack Naming Conventions for Design Patterns ● If an interface has only a single implementation, the implementing class has a suffix Impl ● A class that maps to a database table is known as a Value Object and is suffixed with VO: e.g., NetworkVO. This actually maps to the EJB DTO pattern rather than the EJB VO pattern. ● A class that transfers data from one tier to another (e.g., from the business logic tier to the resource layer) is a Transfer Object and is suffixed withTO: e.g., LoadBalancerTO. ● A utility class that encapsulates common utilities (e.g., conversion between ip address formats) is suffixed with Utils: e.g., NetUtils. These classes do not hold state. Generally all methods are static.
  • 24. References. Additional References: ● Java Programming Style Guidelines ● Java Code Conventions ● http://www.mongodb.org/about/contributors/kernel-code-style/ ● https://code.google.com/p/google-styleguide/ ● http://cloudstack.apache.org/develop/coding-conventions.html ● http://en.wikipedia.org/wiki/Code_refactoring ● http://en.wikipedia.org/wiki/Code_smell ● http://en.wikipedia.org/wiki/God_object

Editor's Notes

  1. Code smell : The term appears to have been coined by Kent Beck on WardsWiki in the late 1990s. Usage of the term increased after it was featured in Refactoring: Improving the Design of Existing Code.[1]Code smell is also a term used by agile programmers.[2] http://en.wikipedia.org/wiki/Code_smell http://en.wikipedia.org/wiki/God_object
  2. http://en.wikipedia.org/wiki/Code_refactoring
  3. http://www.mongodb.org/about/contributors/kernel-code-style/ https://code.google.com/p/google-styleguide/ http://cloudstack.apache.org/develop/coding-conventions.html
  4. http://geosoft.no/development/javastyle.html