SlideShare une entreprise Scribd logo
1  sur  49
BCN } JUG

BE CLEAN, MY FRIEND
A modest review of
Robert C. Martin
“Clean Code, A handbook of Agile Craftmanship”
book
{ THANK YOU ALL }

BCN } JUG
{ DO WE NEED TO CODE BETTER? }

{ Motivation }

BCN } JUG
{ MAIN QUESTION: WHY? }
1. You want to be a good
programmer
1. You want to be better
programmer
1. You like being part of
best teams.
{ Motivation }

BCN } JUG
{ REALLY ?? ?? }
int d; // elapsed time in days
or
int elapsedTimeInDays;
int daysSinceCreation;
int fileAgeInDays;

{ Motivation }

BCN } JUG
{ WHAT IS CLEAN CODE ?? }
Complex things
=
composition of simple things.

Set of techniques to help us achieve
complexity from simplicity.
{ Concepts }

BCN } JUG
{ TABLE OF CONTENTS }
❏ Baptism
❏ What & how are you building?

❏ Unexpected things
❏ What’s inside?
❏ Are you testing?

❏ Before development
❏ Tell me a (beautiful) story
❏ Last, but not least
❏ Recommended readings

BCN } JUG
{ BAPTISM }

/* NAMING GUIDELINES */

BCN } JUG
/* USE INTENTION-REVEALING NAMES */

{ Baptism - Naming guidelines }

BCN } JUG
/* USE INTENTION-REVEALING NAMES */

METHOD CODE

{ Baptism - Naming guidelines }

BCN } JUG
/* USE PRONOUNCEABLE NAMES */

{ Baptism - Naming guidelines }

BCN } JUG
/* CLASSES AND METHODS */
❏ Classes should have noun or noun phrase names
❏ payment
❏ Page
❏ singleUser
❏ BankAccount
❏ myObj

❏ Methods should have verbs or verbs phrase names
❏ postPayment
❏ checkPaymentTransfered
❏ delPag
❏ save
❏ checkUserProfileAllowPaymentByCreditCard
{ Baptism - Naming guidelines }

BCN } JUG
/* CLASSES AND METHODS */

{ Baptism - Naming guidelines }

BCN } JUG
{ WHAT & HOW ARE YOU
BUILDING }
/* CLASSES & METHODS */

BCN } JUG
/* POLYMORPHISM OVER IF/ELSE */

http://www.antiifcampaign.com/
{ Classes & methods }

BCN } JUG
/* FUNCTIONS SHOULD DO ONE THING*/

{ Classes & methods }

BCN } JUG
/* OUTPUT ARGUMENTS */

{ Classes & methods }

BCN } JUG
{ UNEXPECTED THINGS }
/* ERROR HANDLING */

BCN } JUG
/* PREFER EXCEPTIONS TO RETURN CODES
*/

{ Error handling }

BCN } JUG
/* PREFER EXCEPTIONS TO RETURN CODES
*/

{ Error handling }

BCN } JUG
/* DON’T RETURN NULL */

{ Error handling }

BCN } JUG
/* DON’T PASS NULL */

{ Error handling }

BCN } JUG
{ WHAT IS INSIDE? }
/* OBJECTS & DATA STRUCTURES */

BCN } JUG
/* HIDE STRUCTURES */

{ Objects & data structures }

BCN } JUG
/* DATA ABSTRACTION */

{ Objects & data structures }

BCN } JUG
/* DATA TRANSFER OBJECTS */

{ Objects & data structures }

BCN } JUG
/* LAW OF DEMETER */
❏ Each unit should have only limited knowledge about
other units: only units "closely" related to the current
unit.
❏ Each unit should only talk to its friends; don't talk to
strangers.
❏ Only talk to your immediate friends

{ Objects & data structures }

BCN } JUG
/* LAW OF DEMETER */
❏ A method 'm' of a class 'C' may only invoke the
methods of the following kinds of elements:
❏ 'C' itself
❏ 'm's parameters
❏ Any objects created/instantiated within 'm'
❏ ‘C’'s direct component objects
❏ A global variable, accessible by 'C', in the scope
of 'm'

{ Objects & data structures }

BCN } JUG
/* LAW OF DEMETER */

{ Objects & data structures }

BCN } JUG
{ ARE YOU TESTING ? }
/* UNIT TESTING ! */

BCN } JUG
/* USE A COVERAGE TOOL */
Cobertura

Sonar

{ Unit testing }

BCN } JUG
/* TAKE CARE OF TESTS */
❏ Don’t skip trivial tests…
❏ But don’t do ONLY trivial tests!!!
❏ Tests the limits/boundaries of the conditions!
❏ One assert per test!

{ Unit testing }

BCN } JUG
/* KEEP TEST CLEAN */

{ Unit testing }

BCN } JUG
{ BEFORE DEVELOPMENT ... }
/* DESIGN */

BCN } JUG
/* PRINCIPLES & ADVICES */
❏ Don’t repeat yourself (DRY): duplication is evil!

{ Design }

BCN } JUG
/* PRINCIPLES & ADVICES */
❏ Runs all the tests
❏ They will help you
❏ Writing tests leads to better designs!
❏ Refactoring = incrementally improvement
❏ Successive refinement
❏ Separation of main (construction objects <> use)

{ Design }

BCN } JUG
/* FACTORIES */

{ Design }

BCN } JUG
/* DEPENDENCY INJECTION */
With Dependency Injection
(Low dependency with the Interface
and Implementation, because the
Assembler does the job)

Without Dependency Injection

(Hard dependency with the Interface
and Implementation)

{ Design }

BCN } JUG
{ TELL ME A (BEAUTIFUL) STORY }
/* COMMENTS */

BCN } JUG
/* EXPLAIN YOURSELF IN CODE */

{ Comments }

BCN } JUG
/* GOOD COMMENTS */
❏ Legal comments
❏ Informative comments
❏ Explanation of Intent

❏ Warning of Consequences
❏ TODOs

❏ JavaDocs
{ Comments }

BCN } JUG
/* BAD COMMENTS */
/**
* @param title The title
* @param author The author
*/

/**
* Returns the day of the month
*
* @return the day of the month
*/
public int getDayOfMonth() {
return dayOfMonth;
}

/**
* CHANGES
* ------------* 02-Oct-2001 Reorganize process
* 15-Nov-2001 Added new Purchaser type
* 21-Nov-2001 Some customer objects arrive without city set
*/

{ Comments }

BCN } JUG
{ LAST, BUT NOT LEAST }

BCN } JUG
/* THINK ABOUT IT */
❏ This is not a mantra
❏ (Try to) know your environment!

❏ Code is always live
❏ Refactor & test, test & refactor

{ Last, but not least }

BCN } JUG
/* BE CAREFUL */

Always code as if the guy who ends up
maintaining your code will be a violent
psychopath who knows where you live.
John F. Woods
{ Last, but not least }

BCN } JUG
{ DO YOU LIKE IT ?? READ IT ... }
Clean Code, A Handbook of Agile Software Craftmanship
Robert C. Martin
Publication date: August 11, 2008
ISBN-13: 978-0132350884

{ ... OR ... WATCH IT !! }

http://cleancoders.com/

BCN } JUG
{ RECOMMENDED READINGS }
Effective Java (2nd edition)
Joshua Bloch
Publication Date: May 28, 2008
ISBN-13: 978-0321356680

Thinking in Java (4rd edition)
Bruce Eckel
Publication Date: February 20, 2006
ISBN-13: 978-0131872486

BCN } JUG
{ RECOMMENDED READINGS }
Design Patterns: Elements of Reusable
Object-Oriented Software
Erich Gamma, Richard Helm, Ralph Johnson,
John Vlissides
Publication Date: November 10, 1994
ISBN-13: 978-0201633610

Refactoring: Improving the Design
of Existing Code
Martin Fowler, Kent Beck, John Brant,
William Opdyke, Don Roberts
Publication Date: July 8, 1999
ISBN-13: 978-0201485677
BCN } JUG
Thank you !
public static void main (String[] args) {
Author bookAuthor = new Author (“Robert”,”C.Martin”);
String bookTitle = “Clean Code, A handbook of Agile
Craftmanship”;
Book cleanCodeBook = new Book(bookTitle, bookAuthor);
Engineer esteve = new Engineer(“@pensashure”);
Engineer nacho = new Engineer(“@icougil”);
Review review = new Review(cleanCodeBook);
review.perform( Arrays.asList(esteve, nacho) );
System.out.println(“THANKS FOR YOUR ATTENTION”);
}

@BarcelonaJUG

BCN } JUG

Contenu connexe

Similaire à Be clean, my friend (Clean code review by BarcelonaJUG)

Perl Behavior Driven Development (BDD)
Perl Behavior Driven Development (BDD)Perl Behavior Driven Development (BDD)
Perl Behavior Driven Development (BDD)Tudor Constantin
 
Kernel Recipes 2014 - Writing Code: Keep It Short, Stupid!
Kernel Recipes 2014 - Writing Code: Keep It Short, Stupid!Kernel Recipes 2014 - Writing Code: Keep It Short, Stupid!
Kernel Recipes 2014 - Writing Code: Keep It Short, Stupid!Anne Nicolas
 
Precog & MongoDB User Group: Skyrocket Your Analytics
Precog & MongoDB User Group: Skyrocket Your Analytics Precog & MongoDB User Group: Skyrocket Your Analytics
Precog & MongoDB User Group: Skyrocket Your Analytics MongoDB
 
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLEAN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLEGavin Pickin
 
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE - CFObjective() 2017
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE - CFObjective() 2017AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE - CFObjective() 2017
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE - CFObjective() 2017Ortus Solutions, Corp
 
Measure and Improve code quality. Using automation.
Measure and Improve code quality.  Using automation.Measure and Improve code quality.  Using automation.
Measure and Improve code quality. Using automation.Vladimir Korolev
 
Commenting in Agile Development
Commenting in Agile DevelopmentCommenting in Agile Development
Commenting in Agile DevelopmentJan Rybák Benetka
 
Introduction to nand2 tetris
Introduction to nand2 tetrisIntroduction to nand2 tetris
Introduction to nand2 tetrisYodalee
 
AOT-compilation of JavaScript with V8
AOT-compilation of JavaScript with V8AOT-compilation of JavaScript with V8
AOT-compilation of JavaScript with V8Phil Eaton
 
GeeCon.cz - Integration Testing from the Trenches Rebooted
GeeCon.cz  - Integration Testing from the Trenches RebootedGeeCon.cz  - Integration Testing from the Trenches Rebooted
GeeCon.cz - Integration Testing from the Trenches RebootedNicolas Fränkel
 
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
3 Ways to test your ColdFusion API - 2017 Adobe CF SummitOrtus Solutions, Corp
 
Constructor & destructor
Constructor & destructorConstructor & destructor
Constructor & destructorSaharsh Anand
 
2014-06-26 - A guide to undefined behavior in c and c++
2014-06-26 - A guide to undefined behavior in c and c++2014-06-26 - A guide to undefined behavior in c and c++
2014-06-26 - A guide to undefined behavior in c and c++Chen-Han Hsiao
 
Missing objects: ?. and ?? in JavaScript (BrazilJS 2018)
Missing objects: ?. and ?? in JavaScript (BrazilJS 2018)Missing objects: ?. and ?? in JavaScript (BrazilJS 2018)
Missing objects: ?. and ?? in JavaScript (BrazilJS 2018)Igalia
 
LAS16-201: ART JIT in Android N
LAS16-201: ART JIT in Android NLAS16-201: ART JIT in Android N
LAS16-201: ART JIT in Android NLinaro
 
Outside-in Test Driven Development - the London School of TDD
Outside-in Test Driven Development - the London School of TDDOutside-in Test Driven Development - the London School of TDD
Outside-in Test Driven Development - the London School of TDDPeter Kofler
 
Keeping code clean
Keeping code cleanKeeping code clean
Keeping code cleanBrett Child
 

Similaire à Be clean, my friend (Clean code review by BarcelonaJUG) (20)

Perl Behavior Driven Development (BDD)
Perl Behavior Driven Development (BDD)Perl Behavior Driven Development (BDD)
Perl Behavior Driven Development (BDD)
 
Kernel Recipes 2014 - Writing Code: Keep It Short, Stupid!
Kernel Recipes 2014 - Writing Code: Keep It Short, Stupid!Kernel Recipes 2014 - Writing Code: Keep It Short, Stupid!
Kernel Recipes 2014 - Writing Code: Keep It Short, Stupid!
 
Precog & MongoDB User Group: Skyrocket Your Analytics
Precog & MongoDB User Group: Skyrocket Your Analytics Precog & MongoDB User Group: Skyrocket Your Analytics
Precog & MongoDB User Group: Skyrocket Your Analytics
 
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLEAN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE
 
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE - CFObjective() 2017
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE - CFObjective() 2017AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE - CFObjective() 2017
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE - CFObjective() 2017
 
Measure and Improve code quality. Using automation.
Measure and Improve code quality.  Using automation.Measure and Improve code quality.  Using automation.
Measure and Improve code quality. Using automation.
 
Commenting in Agile Development
Commenting in Agile DevelopmentCommenting in Agile Development
Commenting in Agile Development
 
Introduction to nand2 tetris
Introduction to nand2 tetrisIntroduction to nand2 tetris
Introduction to nand2 tetris
 
AOT-compilation of JavaScript with V8
AOT-compilation of JavaScript with V8AOT-compilation of JavaScript with V8
AOT-compilation of JavaScript with V8
 
visualbasic.ppt
visualbasic.pptvisualbasic.ppt
visualbasic.ppt
 
GeeCon.cz - Integration Testing from the Trenches Rebooted
GeeCon.cz  - Integration Testing from the Trenches RebootedGeeCon.cz  - Integration Testing from the Trenches Rebooted
GeeCon.cz - Integration Testing from the Trenches Rebooted
 
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
 
Constructor & destructor
Constructor & destructorConstructor & destructor
Constructor & destructor
 
Hexagonal architecture
Hexagonal architectureHexagonal architecture
Hexagonal architecture
 
2014-06-26 - A guide to undefined behavior in c and c++
2014-06-26 - A guide to undefined behavior in c and c++2014-06-26 - A guide to undefined behavior in c and c++
2014-06-26 - A guide to undefined behavior in c and c++
 
Missing objects: ?. and ?? in JavaScript (BrazilJS 2018)
Missing objects: ?. and ?? in JavaScript (BrazilJS 2018)Missing objects: ?. and ?? in JavaScript (BrazilJS 2018)
Missing objects: ?. and ?? in JavaScript (BrazilJS 2018)
 
LAS16-201: ART JIT in Android N
LAS16-201: ART JIT in Android NLAS16-201: ART JIT in Android N
LAS16-201: ART JIT in Android N
 
Outside-in Test Driven Development - the London School of TDD
Outside-in Test Driven Development - the London School of TDDOutside-in Test Driven Development - the London School of TDD
Outside-in Test Driven Development - the London School of TDD
 
Keeping code clean
Keeping code cleanKeeping code clean
Keeping code clean
 
How to start test automation
How to start test automationHow to start test automation
How to start test automation
 

Plus de Nacho Cougil

TDD - Seriously, try it! - Opensouthcode
TDD - Seriously, try it! - OpensouthcodeTDD - Seriously, try it! - Opensouthcode
TDD - Seriously, try it! - OpensouthcodeNacho Cougil
 
TDD - Seriously, try it! - Bucarest Tech Week
TDD - Seriously, try it! - Bucarest Tech WeekTDD - Seriously, try it! - Bucarest Tech Week
TDD - Seriously, try it! - Bucarest Tech WeekNacho Cougil
 
TDD - Seriously, try it! - Trjjmiasto JUG (17th May '23)
TDD - Seriously, try it! - Trjjmiasto JUG (17th May '23)TDD - Seriously, try it! - Trjjmiasto JUG (17th May '23)
TDD - Seriously, try it! - Trjjmiasto JUG (17th May '23)Nacho Cougil
 
TDD - Seriously, try it! (updated '22)
TDD - Seriously, try it! (updated '22)TDD - Seriously, try it! (updated '22)
TDD - Seriously, try it! (updated '22)Nacho Cougil
 
Refactor your code: when, why and how (revisited)
Refactor your code: when, why and how (revisited)Refactor your code: when, why and how (revisited)
Refactor your code: when, why and how (revisited)Nacho Cougil
 
TDD: seriously, try it! 
TDD: seriously, try it! TDD: seriously, try it! 
TDD: seriously, try it! Nacho Cougil
 
Refactor your code: when, why and how?
Refactor your code: when, why and how?Refactor your code: when, why and how?
Refactor your code: when, why and how?Nacho Cougil
 
Introduction to TDD
Introduction to TDDIntroduction to TDD
Introduction to TDDNacho Cougil
 
BarcelonaJUG at GDG summit
BarcelonaJUG at GDG summitBarcelonaJUG at GDG summit
BarcelonaJUG at GDG summitNacho Cougil
 
Seghismed - Disseny i desenvolupament d'un esquema criptogràfic per gestionar...
Seghismed - Disseny i desenvolupament d'un esquema criptogràfic per gestionar...Seghismed - Disseny i desenvolupament d'un esquema criptogràfic per gestionar...
Seghismed - Disseny i desenvolupament d'un esquema criptogràfic per gestionar...Nacho Cougil
 

Plus de Nacho Cougil (11)

TDD - Seriously, try it! - Opensouthcode
TDD - Seriously, try it! - OpensouthcodeTDD - Seriously, try it! - Opensouthcode
TDD - Seriously, try it! - Opensouthcode
 
TDD - Seriously, try it! - Bucarest Tech Week
TDD - Seriously, try it! - Bucarest Tech WeekTDD - Seriously, try it! - Bucarest Tech Week
TDD - Seriously, try it! - Bucarest Tech Week
 
TDD - Seriously, try it! - Trjjmiasto JUG (17th May '23)
TDD - Seriously, try it! - Trjjmiasto JUG (17th May '23)TDD - Seriously, try it! - Trjjmiasto JUG (17th May '23)
TDD - Seriously, try it! - Trjjmiasto JUG (17th May '23)
 
TDD - Seriously, try it! (updated '22)
TDD - Seriously, try it! (updated '22)TDD - Seriously, try it! (updated '22)
TDD - Seriously, try it! (updated '22)
 
Refactor your code: when, why and how (revisited)
Refactor your code: when, why and how (revisited)Refactor your code: when, why and how (revisited)
Refactor your code: when, why and how (revisited)
 
TDD: seriously, try it! 
TDD: seriously, try it! TDD: seriously, try it! 
TDD: seriously, try it! 
 
Refactor your code: when, why and how?
Refactor your code: when, why and how?Refactor your code: when, why and how?
Refactor your code: when, why and how?
 
Introduction to TDD
Introduction to TDDIntroduction to TDD
Introduction to TDD
 
BarcelonaJUG at GDG summit
BarcelonaJUG at GDG summitBarcelonaJUG at GDG summit
BarcelonaJUG at GDG summit
 
Gencat Notifier
Gencat NotifierGencat Notifier
Gencat Notifier
 
Seghismed - Disseny i desenvolupament d'un esquema criptogràfic per gestionar...
Seghismed - Disseny i desenvolupament d'un esquema criptogràfic per gestionar...Seghismed - Disseny i desenvolupament d'un esquema criptogràfic per gestionar...
Seghismed - Disseny i desenvolupament d'un esquema criptogràfic per gestionar...
 

Dernier

Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbuapidays
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 

Dernier (20)

Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 

Be clean, my friend (Clean code review by BarcelonaJUG)

  • 1. BCN } JUG BE CLEAN, MY FRIEND A modest review of Robert C. Martin “Clean Code, A handbook of Agile Craftmanship” book
  • 2. { THANK YOU ALL } BCN } JUG
  • 3. { DO WE NEED TO CODE BETTER? } { Motivation } BCN } JUG
  • 4. { MAIN QUESTION: WHY? } 1. You want to be a good programmer 1. You want to be better programmer 1. You like being part of best teams. { Motivation } BCN } JUG
  • 5. { REALLY ?? ?? } int d; // elapsed time in days or int elapsedTimeInDays; int daysSinceCreation; int fileAgeInDays; { Motivation } BCN } JUG
  • 6. { WHAT IS CLEAN CODE ?? } Complex things = composition of simple things. Set of techniques to help us achieve complexity from simplicity. { Concepts } BCN } JUG
  • 7. { TABLE OF CONTENTS } ❏ Baptism ❏ What & how are you building? ❏ Unexpected things ❏ What’s inside? ❏ Are you testing? ❏ Before development ❏ Tell me a (beautiful) story ❏ Last, but not least ❏ Recommended readings BCN } JUG
  • 8. { BAPTISM } /* NAMING GUIDELINES */ BCN } JUG
  • 9. /* USE INTENTION-REVEALING NAMES */ { Baptism - Naming guidelines } BCN } JUG
  • 10. /* USE INTENTION-REVEALING NAMES */ METHOD CODE { Baptism - Naming guidelines } BCN } JUG
  • 11. /* USE PRONOUNCEABLE NAMES */ { Baptism - Naming guidelines } BCN } JUG
  • 12. /* CLASSES AND METHODS */ ❏ Classes should have noun or noun phrase names ❏ payment ❏ Page ❏ singleUser ❏ BankAccount ❏ myObj ❏ Methods should have verbs or verbs phrase names ❏ postPayment ❏ checkPaymentTransfered ❏ delPag ❏ save ❏ checkUserProfileAllowPaymentByCreditCard { Baptism - Naming guidelines } BCN } JUG
  • 13. /* CLASSES AND METHODS */ { Baptism - Naming guidelines } BCN } JUG
  • 14. { WHAT & HOW ARE YOU BUILDING } /* CLASSES & METHODS */ BCN } JUG
  • 15. /* POLYMORPHISM OVER IF/ELSE */ http://www.antiifcampaign.com/ { Classes & methods } BCN } JUG
  • 16. /* FUNCTIONS SHOULD DO ONE THING*/ { Classes & methods } BCN } JUG
  • 17. /* OUTPUT ARGUMENTS */ { Classes & methods } BCN } JUG
  • 18. { UNEXPECTED THINGS } /* ERROR HANDLING */ BCN } JUG
  • 19. /* PREFER EXCEPTIONS TO RETURN CODES */ { Error handling } BCN } JUG
  • 20. /* PREFER EXCEPTIONS TO RETURN CODES */ { Error handling } BCN } JUG
  • 21. /* DON’T RETURN NULL */ { Error handling } BCN } JUG
  • 22. /* DON’T PASS NULL */ { Error handling } BCN } JUG
  • 23. { WHAT IS INSIDE? } /* OBJECTS & DATA STRUCTURES */ BCN } JUG
  • 24. /* HIDE STRUCTURES */ { Objects & data structures } BCN } JUG
  • 25. /* DATA ABSTRACTION */ { Objects & data structures } BCN } JUG
  • 26. /* DATA TRANSFER OBJECTS */ { Objects & data structures } BCN } JUG
  • 27. /* LAW OF DEMETER */ ❏ Each unit should have only limited knowledge about other units: only units "closely" related to the current unit. ❏ Each unit should only talk to its friends; don't talk to strangers. ❏ Only talk to your immediate friends { Objects & data structures } BCN } JUG
  • 28. /* LAW OF DEMETER */ ❏ A method 'm' of a class 'C' may only invoke the methods of the following kinds of elements: ❏ 'C' itself ❏ 'm's parameters ❏ Any objects created/instantiated within 'm' ❏ ‘C’'s direct component objects ❏ A global variable, accessible by 'C', in the scope of 'm' { Objects & data structures } BCN } JUG
  • 29. /* LAW OF DEMETER */ { Objects & data structures } BCN } JUG
  • 30. { ARE YOU TESTING ? } /* UNIT TESTING ! */ BCN } JUG
  • 31. /* USE A COVERAGE TOOL */ Cobertura Sonar { Unit testing } BCN } JUG
  • 32. /* TAKE CARE OF TESTS */ ❏ Don’t skip trivial tests… ❏ But don’t do ONLY trivial tests!!! ❏ Tests the limits/boundaries of the conditions! ❏ One assert per test! { Unit testing } BCN } JUG
  • 33. /* KEEP TEST CLEAN */ { Unit testing } BCN } JUG
  • 34. { BEFORE DEVELOPMENT ... } /* DESIGN */ BCN } JUG
  • 35. /* PRINCIPLES & ADVICES */ ❏ Don’t repeat yourself (DRY): duplication is evil! { Design } BCN } JUG
  • 36. /* PRINCIPLES & ADVICES */ ❏ Runs all the tests ❏ They will help you ❏ Writing tests leads to better designs! ❏ Refactoring = incrementally improvement ❏ Successive refinement ❏ Separation of main (construction objects <> use) { Design } BCN } JUG
  • 37. /* FACTORIES */ { Design } BCN } JUG
  • 38. /* DEPENDENCY INJECTION */ With Dependency Injection (Low dependency with the Interface and Implementation, because the Assembler does the job) Without Dependency Injection (Hard dependency with the Interface and Implementation) { Design } BCN } JUG
  • 39. { TELL ME A (BEAUTIFUL) STORY } /* COMMENTS */ BCN } JUG
  • 40. /* EXPLAIN YOURSELF IN CODE */ { Comments } BCN } JUG
  • 41. /* GOOD COMMENTS */ ❏ Legal comments ❏ Informative comments ❏ Explanation of Intent ❏ Warning of Consequences ❏ TODOs ❏ JavaDocs { Comments } BCN } JUG
  • 42. /* BAD COMMENTS */ /** * @param title The title * @param author The author */ /** * Returns the day of the month * * @return the day of the month */ public int getDayOfMonth() { return dayOfMonth; } /** * CHANGES * ------------* 02-Oct-2001 Reorganize process * 15-Nov-2001 Added new Purchaser type * 21-Nov-2001 Some customer objects arrive without city set */ { Comments } BCN } JUG
  • 43. { LAST, BUT NOT LEAST } BCN } JUG
  • 44. /* THINK ABOUT IT */ ❏ This is not a mantra ❏ (Try to) know your environment! ❏ Code is always live ❏ Refactor & test, test & refactor { Last, but not least } BCN } JUG
  • 45. /* BE CAREFUL */ Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. John F. Woods { Last, but not least } BCN } JUG
  • 46. { DO YOU LIKE IT ?? READ IT ... } Clean Code, A Handbook of Agile Software Craftmanship Robert C. Martin Publication date: August 11, 2008 ISBN-13: 978-0132350884 { ... OR ... WATCH IT !! } http://cleancoders.com/ BCN } JUG
  • 47. { RECOMMENDED READINGS } Effective Java (2nd edition) Joshua Bloch Publication Date: May 28, 2008 ISBN-13: 978-0321356680 Thinking in Java (4rd edition) Bruce Eckel Publication Date: February 20, 2006 ISBN-13: 978-0131872486 BCN } JUG
  • 48. { RECOMMENDED READINGS } Design Patterns: Elements of Reusable Object-Oriented Software Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides Publication Date: November 10, 1994 ISBN-13: 978-0201633610 Refactoring: Improving the Design of Existing Code Martin Fowler, Kent Beck, John Brant, William Opdyke, Don Roberts Publication Date: July 8, 1999 ISBN-13: 978-0201485677 BCN } JUG
  • 49. Thank you ! public static void main (String[] args) { Author bookAuthor = new Author (“Robert”,”C.Martin”); String bookTitle = “Clean Code, A handbook of Agile Craftmanship”; Book cleanCodeBook = new Book(bookTitle, bookAuthor); Engineer esteve = new Engineer(“@pensashure”); Engineer nacho = new Engineer(“@icougil”); Review review = new Review(cleanCodeBook); review.perform( Arrays.asList(esteve, nacho) ); System.out.println(“THANKS FOR YOUR ATTENTION”); } @BarcelonaJUG BCN } JUG