Systems Analysis and Design
CT026-3-1
Coding Standards and Principles
Topic & Structure of The
Lesson
• Implementation
– Coding Standards
– Principles of Good Programming
CT026-3-1 Systems Analysis and Design Coding Standards and Principles Page 2 of 19
Learning Outcomes
• By the end of this lecture, YOU
should be able to :
• Discuss Coding Standards and
Principles
• Discuss benefits of coding standards
• Discuss good programming practices
CT026-3-1 Systems Analysis and Design Coding Standards and Principles Page 3 of 19
Key Terms you must be able to use
• If you have mastered this topic, you should
be able to use the following terms correctly
in your assignments and exams:
– Coding best practices
– Variable naming
– Maintainable code
– Bad smells
– Refactoring
CT026-3-1 Systems Analysis and Design Coding Standards and Principles Page 4 of 19
Coding Standards
• Code not only needs to do its job well, but
must also be easy to add to, maintain and
debug.
• Needing to make changes to code could require
a lot of energy to decipher lines of code that
doesn’t make its purpose or intentions clear.
• Neatly commented with details that explain any
complicated constructs and the reasoning
behind them.
CT026-3-1 Systems Analysis and Design Coding Standards and Principles Page 5 of 19
Coding Standards
• A coding standards document tells
developers how they must write their code.
• Avoid each developer coding in their own
preferred style
• Large project is coded in a consistent style
– parts are not written differently by different
programmers.
CT026-3-1 Systems Analysis and Design Coding Standards and Principles Page 6 of 19
Why do we need coding
standards?
• Consistent look
• Improve readability
• Simplifies copying, editing and
maintenance
• Company wide standardization
CT026-3-1 Systems Analysis and Design Coding Standards and Principles Page 7 of 19
Principles of Good Programming
• KISS – Keep It Short and Simple
• DRY - Don’t Repeat Yourself
• Abstraction - Each significant piece of
functionality in a program should be
implemented in just one place in the source
code
• Open/Closed Principle - Software entities
(classes, modules, functions, etc.) should be
open for extension, but closed for modification.
– don't write classes that people can modify, write
classes that people can extend
CT026-3-1 Systems Analysis and Design Coding Standards and Principles Page 8 of 19
Principles of Good Programming
• Single Responsibility Principle - A component of
code (e.g. class or function) should perform a
single well defined task.
CT026-3-1 Systems Analysis and Design Coding Standards and Principles Page 9 of 19
Principles of Good Programming
• Minimize Coupling - Any section of code (code
block, function, class, etc) should minimize the
dependencies on other areas of code.
– using shared variables as little as possible.
• Maximize Cohesion - Code that has similar
functionality should be found within the same
component
CT026-3-1 Systems Analysis and Design Coding Standards and Principles Page 10 of 19
Naming Conventions
• No abbreviations
– OnButtonClick vs OnBtnClk
• Meaningful names
– Intention revealing
• int t; //Time to complete single lap
• int singleLapTime;
CT026-3-1 Systems Analysis and Design Coding Standards and Principles Page 11 of 19
Naming Conventions
Variable Names: Variable names should be in all lowercase, with
words separated by an underscore, example:
Incorrect:
$currentuser
$currentUser
Correct:
$current_user
Names should be descriptive, but concise. We don't want huge
sentences as our variable names, but typing an extra couple of
characters is always better than wondering what exactly a certain
variable is for.
CT026-3-1 Systems Analysis and Design Coding Standards and Principles Page 12 of 19
Loop Indices
for ($i = 0; $i < $outer_size; $i++)
{
for ($j = 0; $j < $inner_size; $j++)
{
foo($i, $j);
}
}
CT026-3-1 Systems Analysis and Design Coding Standards and Principles Page 13 of 19
Code Smells
• Duplicated code
• Large classes
• Long methods
• Long parameter list
CT026-3-1 Systems Analysis and Design Coding Standards and Principles Page 14 of 19
Refactoring
• improve your software internal structure in a safe way
while not changing / adding / removing behavior or
external interfaces.
• +readable code, +simplified code, +easier to change,
+easier to add new value, +reduced redundancy, advices
how to go on to keep-improve software, and last but not
least +automatic tests.
CT026-3-1 Systems Analysis and Design Coding Standards and Principles Page 15 of 19
Quick Review Question
CT026-3-1 Systems Analysis and Design Coding Standards and Principles Page 16 of 19
Summary of Main Teaching Points
• Input Design
– Coding Standards
– Principles of Good Programming
CT026-3-1 Systems Analysis and Design Coding Standards and Principles Page 17 of 19
Question and Answer
Session
Q&A
CT026-3-1 Systems Analysis and Design Coding Standards and Principles Page 18 of 19
What we will cover next
• Implementation
– Types of testing
– Test plan
CT026-3-1 Systems Analysis and Design Coding Standards and Principles Page 19 of 19