SlideShare a Scribd company logo
Clean Code
What is Bad Code and Good code
Hello world!
I AM JEREMIAH CABALLERO
● I am Web Development Team Lead
in Sun*Philippines
● Advocate of Clean Architecture
and Clean Code
● Active member of Laravel
Cebu,ReactJS Cebu, Javascript
Cebu and Vue.js Cebu.
● Have my own community which is
Cod_ex.
2
Hello world!
I AM JEREMIAH CABALLERO
● You can follow me on:
Medium: @jeremiah.caballero.jc
Instagram: @caballerojeremiah
Twitter: @jkablyero
3
4
Outline
To what we will discuss
● Clean Code
● Meaningful Names
● Functions
● Comments
5
Master programmers think of
systems as stories to be told
rather than programs to be
written
-Robert C. Martin
6
1
CLEAN CODE
What and Why is Clean
Code?
7
BAD CODE
Bad Code are hard to read,
maintain and test
8
ART OF CLEAN CODE
Consider Code as a Piece of Art.
9
Jeremiah Caballero - Introduction of Clean Code
Jeremiah Caballero - Introduction of Clean Code
WHAT IS CLEAN CODE
To Write code with Elegance
12
Dictionary says
El·e·gance /ˈeləɡəns/
noun
1. the quality of being graceful and
stylish in appearance or
manner; style.
13
2
MEANINGFUL NAMES
Names are everywhere in
software.
14
USE INTENTION-REVEALING
NAMES
It is easy to say that names
should reveal intent.
15
//store last name and
first name
$x;
$y;
$firstname;
$lastname;
$x = [0,1,2,3];
function getThem () {
foreach($x as $num) {
return num;
};
}
What does it mean?
● What does x mean?
● What does it get?
● What is num?
19
$numberSequence = [0,1,2,3];
function getEachNumberFromSeq() {
foreach($numberSequence as $number) {
echo $number;
}
}
USE PRONOUNCEABLE NAMES
Just like words code is
pronounceable.
21
class DtaRcrd102 {
private $genymdhms;
private $modymdhms;
private $pszqint = ”102”;
}
class Customer {
private $generationTimestamp;
private $modificationTimestamp;
private $recordId = ”102”;
}
USE SEARCHABLE NAMES
Name your variable or function
that can be search easily
24
for (int j=0; j<34; j++) {
s += (t[j]*4)/5;
}
//constant variable
define(“WORK_DAYS_PER_WEEK”, 5);
$realDaysPerIdealDay = 4;
$sum = 0;
for ($j=0; $j < NUMBER_OF_TASKS; $j++) {
$realTaskDays = $taskEstimate[j] * $realDaysPerIdealDay;
$realTaskWeeks = ($realdays / WORK_DAYS_PER_WEEK);
//code here
}
METHOD NAMES
Methods should have verb or
verb phrase
27
Verb Methods
get();
save();
deletePost();
28
function getList() {
//code here
}
3
Functions
Name that function
30
SMALL!
The first rule of functions is
that they should be small.
31
public static renderPageWithSetupsAndTeardowns(
PageData $pageData, $isSuite
) throws Exception {
$isTestPage = $pageData.hasAttribute("Test");
if ($isTestPage) {
$testPage = pageData.getWikiPage();
$newPageContent = new StringBuffer();
includeSetupPages(testPage, newPageContent, isSuite);
newPageContent.append(pageData.getContent());
includeTeardownPages(testPage, newPageContent, isSuite);
$pageData.setContent(newPageContent.toString());
}
return $pageData.getHtml();
}
public static renderPageWith(PageData $pageData, $isSuite)
throws Exception {
if (isTestPage($pageData))
includeSetupAndTeardownPages($pageData, $isSuite);
return $pageData.getHtml();
}
DO ONE THING
A function must do one thing
34
public static renderPageWithSetupsAndTeardowns(
PageData $pageData, $isSuite
) throws Exception {
$isTestPage = $pageData.hasAttribute("Test");
if ($isTestPage) {
$testPage = pageData.getWikiPage();
$newPageContent = new StringBuffer();
includeSetupPages(testPage, newPageContent, isSuite);
newPageContent.append(pageData.getContent());
includeTeardownPages(testPage, newPageContent, isSuite);
$pageData.setContent(newPageContent.toString());
}
return $pageData.getHtml();
}
DO ONE THING
1. Determining whether the page is a test
page.
2. If so, including setups and teardowns.
3. Rendering the page in HTML.
36
public static renderPageWith(PageData $pageData, $isSuite)
throws Exception {
if (isTestPage($pageData))
includeSetupAndTeardownPages($pageData, $isSuite);
return $pageData.getHtml();
}
4
Comments
Explain yourself
38
GOOD COMMENTS
Some comments are necessary or
beneficial.
39
LEGAL COMMENTS
40
// Copyright (C) 2003,2004,2005 by Object
Mentor, Inc. All rights reserved.
// Released under the terms of the GNU
General Public License version 2 or later.
INFORMATIVE COMMENTS
41
// Returns an instance of the
Responder being tested.
protected abstract Responder
responderInstance();
WARNING OF CONSEQUENCES
42
// Don't run unless you
// have some time to kill.
public function testWithReallyBigFile()
{
writeLinesToFile(10000000);
$response.setBody(testFile);
$response.readyToSend(this);
$responseString = $output.toString();
assertSubString("Content-Length: 1000000000",
$responseString);
assertTrue($bytesSent > 1000000000);
}
BAD COMMENTS
If there is good comments there
is bad comments also.
43
REDUNDANT COMMENTS
44
// Utility method that returns when this.closed is true. Throws
an exception
// if the timeout is reached.
public waitForClose(RtimeoutMillis)
{
if(!$closed)
{
wait($timeoutMillis);
if(!$closed)
throw new Exception("MockResponseSender could not be
closed");
}
}
NOISE COMMENTS
45
/** The day of the month. */
private $dayOfMonth;
NOISE COMMENTS
46
/** The day of the month. */
private $dayOfMonth;
SCARY NOISE COMMENTS
47
/** The name. */
private $name;
/** The version. */
private $version;
/** The licenceName. */
private $licenceName;
/** The version. */
private $info;
LET’S REVIEW SOME POINTERS
Clean Code
What is clean code and the
purpose why it is written.
MEANINGFUL NAMES
How to write meaningful
names in our code.
FUNCTIONS
How to write functions and
how write functions more
shorter
COMMENTS
How to write comments that
explains the program’s
intent and know how to
identify bad comments.
48
Master programmers think of
systems as stories to be told
rather than programs to be
written
-Robert C. Martin
49
Thanks!
ANY QUESTIONS?
50
51
SlidesCarnival icons are editable
shapes.
This means that you can:
● Resize them without losing
quality.
● Change fill color and
opacity.
Isn’t that nice? :)
Examples:
52
Now you can use any emoji as an icon!
And of course it resizes without losing quality and you can
change the color.
How? Follow Google instructions
https://twitter.com/googledocs/status/730087240156643328
✋👆👉👍👤👦👧👨👩👪💃🏃
💑❤😂😉😋😒😭👶😸🐟🍒🍔
💣📌📖🔨🎃🎈🎨🏈🏰🌏🔌🔑
and many more...
��
53

More Related Content

PPTX
Refactoring group 1 - chapter 3,4,6
PDF
You code sucks, let's fix it
DOCX
Ip project work test your knowledge
KEY
Object Calisthenics Applied to PHP
PDF
Your code sucks, let's fix it - DPC UnCon
PDF
PHP for Adults: Clean Code and Object Calisthenics
PDF
Practical JavaScript Programming - Session 4/8
PPT
Perl Intro 7 Subroutines
Refactoring group 1 - chapter 3,4,6
You code sucks, let's fix it
Ip project work test your knowledge
Object Calisthenics Applied to PHP
Your code sucks, let's fix it - DPC UnCon
PHP for Adults: Clean Code and Object Calisthenics
Practical JavaScript Programming - Session 4/8
Perl Intro 7 Subroutines

What's hot (20)

PDF
Object Calisthenics Adapted for PHP
PPTX
PDF
How to work with legacy code
PDF
How to work with legacy code PHPers Rzeszow #2
PDF
Closer look at PHP Unserialization by Ashwin Shenoi
PDF
Design Patterns
PPTX
Hacking Your Way To Better Security - Dutch PHP Conference 2016
PDF
IP project for class 12 cbse
PDF
Design Patterns Reconsidered
PDF
Coding website
PDF
Dependency Injection
PPT
Php variables
PDF
AST + Better Reflection (PHP Benelux 2016 Unconference)
PDF
Resultados
PDF
Pim Elshoff "Technically DDD"
DOC
Martin Roy Portfolio
PDF
SOLID Ruby SOLID Rails
PDF
Object-oriented Javascript
PDF
What is DDD and how could it help you
PDF
Clean Code JavaScript
Object Calisthenics Adapted for PHP
How to work with legacy code
How to work with legacy code PHPers Rzeszow #2
Closer look at PHP Unserialization by Ashwin Shenoi
Design Patterns
Hacking Your Way To Better Security - Dutch PHP Conference 2016
IP project for class 12 cbse
Design Patterns Reconsidered
Coding website
Dependency Injection
Php variables
AST + Better Reflection (PHP Benelux 2016 Unconference)
Resultados
Pim Elshoff "Technically DDD"
Martin Roy Portfolio
SOLID Ruby SOLID Rails
Object-oriented Javascript
What is DDD and how could it help you
Clean Code JavaScript
Ad

Similar to Jeremiah Caballero - Introduction of Clean Code (20)

PPTX
Presentacion clean code
 
PDF
Clean code
PDF
Clean code
PPTX
Clean code
PDF
What's in a name
PDF
Save time by applying clean code principles
PDF
PHP: 4 Design Patterns to Make Better Code
PPTX
Clean Code: Chapter 3 Function
PDF
Does your code spark joy? Refactoring techniques to make your life easier.
PDF
Clean Code 2
PDF
4Developers 2015: Be pragmatic, be SOLID - Krzysztof Menżyk
PDF
Be pragmatic, be SOLID
PDF
Alexander Makarov "Let’s talk about code"
PDF
PHPSpec BDD Framework
PPTX
10 ways to make your code rock
PDF
The IoC Hydra - Dutch PHP Conference 2016
PPTX
clean code book summary - uncle bob - English version
PPTX
Clean code slide
PPTX
SOLID, DRY, SLAP design principles
PDF
Clean code & design patterns
Presentacion clean code
 
Clean code
Clean code
Clean code
What's in a name
Save time by applying clean code principles
PHP: 4 Design Patterns to Make Better Code
Clean Code: Chapter 3 Function
Does your code spark joy? Refactoring techniques to make your life easier.
Clean Code 2
4Developers 2015: Be pragmatic, be SOLID - Krzysztof Menżyk
Be pragmatic, be SOLID
Alexander Makarov "Let’s talk about code"
PHPSpec BDD Framework
10 ways to make your code rock
The IoC Hydra - Dutch PHP Conference 2016
clean code book summary - uncle bob - English version
Clean code slide
SOLID, DRY, SLAP design principles
Clean code & design patterns
Ad

Recently uploaded (20)

PDF
Designing Intelligence for the Shop Floor.pdf
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
Digital Systems & Binary Numbers (comprehensive )
PDF
System and Network Administraation Chapter 3
PDF
System and Network Administration Chapter 2
PPTX
L1 - Introduction to python Backend.pptx
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PDF
Understanding Forklifts - TECH EHS Solution
PDF
medical staffing services at VALiNTRY
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Designing Intelligence for the Shop Floor.pdf
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Digital Systems & Binary Numbers (comprehensive )
System and Network Administraation Chapter 3
System and Network Administration Chapter 2
L1 - Introduction to python Backend.pptx
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
Understanding Forklifts - TECH EHS Solution
medical staffing services at VALiNTRY
VVF-Customer-Presentation2025-Ver1.9.pptx
Which alternative to Crystal Reports is best for small or large businesses.pdf
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
wealthsignaloriginal-com-DS-text-... (1).pdf
How to Migrate SBCGlobal Email to Yahoo Easily
Navsoft: AI-Powered Business Solutions & Custom Software Development
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
How to Choose the Right IT Partner for Your Business in Malaysia
Design an Analysis of Algorithms II-SECS-1021-03
2025 Textile ERP Trends: SAP, Odoo & Oracle
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...

Jeremiah Caballero - Introduction of Clean Code