Clean Code Principle
Muhammad Ali
Muhammad Ali and Zohaib Masood
Zohaib Masood
Overview
Why Clean Code?
Principles of Clean Code
DRY
KISS
SOC
Design by Contract
Muhammad Ali and Zohaib Masood
Clean Code
Code should be easily readable
Code should be easily understandable
Code should be easily modified by anyone
Muhammad Ali and Zohaib Masood
Keep It Simple and Stupid
Whenever we want to implement
a method to do all things
Muhammad Ali and Zohaib Masood
Keep It Simple and Stupid
Solve more problems, faster.
Code complex problems in few lines of code
Produce higher quality code
Achieve more than you imagined
Work in large development groups and large projects
since all the code is stupid simple
Muhammad Ali and Zohaib Masood
Don’t Repeat Yourself
A principle of software development, aimed at reducing
repetition of information of all kinds.
• Applicable whenever we Copy / paste
a piece of code
• Just use a method or a class
Muhammad Ali and Zohaib Masood
Don’t Repeat Yourself
Very simple and not worth exploring too much.
Don't write the same stuff in multiple places, or you
will have to keep them synchronized at every change.
Simply don't repeat yourself.
Muhammad Ali and Zohaib Masood
Separation Of Concern
Design principle which states that each element of a
program should address a single concern
Core concern represents a single
and primary functionality
Cross cutting concern is
applicable throughout the system
Muhammad Ali and Zohaib Masood
Separation Of Concern
Functional Concerns
Quality of service
Policy
System
Organization
Muhammad Ali and Zohaib Masood
Separation Of Concern
A class should have a specific purpose and it should
be used for that purpose only.
It should be easy to extend and update whenever
required, and designed in such a way that testing do
not affect it.
Each functionality should be considered as a
separate concern and should not affect each other.
Muhammad Ali and Zohaib Masood
Design by Contract
Design by Contract (DBC) is a software correctness
technique that ensures high-quality software
systems by guaranteeing that every component of
the system lives up to its expectations.
Muhammad Ali and Zohaib Masood
Design by Contract
Pre-conditions: conditions that should exist before
a method can execute.
Post-conditions: conditions that should hold after a
method completes.
Invariants: predicates that should hold at certain
points in the execution of a program.
Muhammad Ali and Zohaib Masood
Thank You
Muhammad Ali and Zohaib Masood