SlideShare a Scribd company logo
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

More Related Content

PPTX
Clean code
Simon Sƶnnby
Ā 
PPTX
Writing Clean Code (Recommendations by Robert Martin)
Shirish Bari
Ā 
PPTX
Clean Code III - Software Craftsmanship
Theo Jungeblut
Ā 
PPT
Clean Code summary
Jan de Vries
Ā 
PPTX
Clean Code Part III - Craftsmanship at SoCal Code Camp
Theo Jungeblut
Ā 
PDF
Clean Code V2
Jean Carlo Machado
Ā 
PDF
Clean Code. An Agile Guide to Software Craft Kameron H.
sagolbencib
Ā 
Clean code
Simon Sƶnnby
Ā 
Writing Clean Code (Recommendations by Robert Martin)
Shirish Bari
Ā 
Clean Code III - Software Craftsmanship
Theo Jungeblut
Ā 
Clean Code summary
Jan de Vries
Ā 
Clean Code Part III - Craftsmanship at SoCal Code Camp
Theo Jungeblut
Ā 
Clean Code V2
Jean Carlo Machado
Ā 
Clean Code. An Agile Guide to Software Craft Kameron H.
sagolbencib
Ā 

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

PDF
Clean Code. An Agile Guide to Software Craft Kameron H.
komvjzfjj621
Ā 
PDF
Clean Code. An Agile Guide to Software Craft Kameron H.
krantzloigu
Ā 
PPTX
clean code book summary - uncle bob - English version
saber tabatabaee
Ā 
PPT
Importance Of Being Driven
Antonio Terreno
Ā 
PDF
Quick Intro to Clean Coding
Ecommerce Solution Provider SysIQ
Ā 
PDF
[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...
DevDay Da Nang
Ā 
PDF
Taming Big Balls of Mud with Diligence, Agile Practices, and Hard Work
Joseph Yoder
Ā 
PPTX
Writing Better Code - Helping Developers make Decisions.pptx
Lorraine Steyn
Ā 
PDF
Clean code
Jean Carlo Machado
Ā 
PPTX
Clean code chpt_1
saber tabatabaee
Ā 
PDF
Simple Pure Java
Anton Keks
Ā 
PPTX
Robert martin
Shiraz316
Ā 
PPTX
Writing clean code in C# and .NET
Dror Helper
Ā 
PDF
Clean Code
Daniel Kummer
Ā 
ODP
Bring the fun back to java
ciklum_ods
Ā 
PDF
Introduction to SOLID Principles
Ganesh Samarthyam
Ā 
PPTX
Clean Code III - Software Craftsmanship at SoCal Code Camp San Diego (07/27/2...
Theo Jungeblut
Ā 
PPTX
Coding Standard And Code Review
Milan Vukoje
Ā 
PPTX
Software Development Practices in Practice
Dennis Doomen
Ā 
PDF
Clean code and code smells
Md. Aftab Uddin Kajal
Ā 
Clean Code. An Agile Guide to Software Craft Kameron H.
komvjzfjj621
Ā 
Clean Code. An Agile Guide to Software Craft Kameron H.
krantzloigu
Ā 
clean code book summary - uncle bob - English version
saber tabatabaee
Ā 
Importance Of Being Driven
Antonio Terreno
Ā 
Quick Intro to Clean Coding
Ecommerce Solution Provider SysIQ
Ā 
[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...
DevDay Da Nang
Ā 
Taming Big Balls of Mud with Diligence, Agile Practices, and Hard Work
Joseph Yoder
Ā 
Writing Better Code - Helping Developers make Decisions.pptx
Lorraine Steyn
Ā 
Clean code
Jean Carlo Machado
Ā 
Clean code chpt_1
saber tabatabaee
Ā 
Simple Pure Java
Anton Keks
Ā 
Robert martin
Shiraz316
Ā 
Writing clean code in C# and .NET
Dror Helper
Ā 
Clean Code
Daniel Kummer
Ā 
Bring the fun back to java
ciklum_ods
Ā 
Introduction to SOLID Principles
Ganesh Samarthyam
Ā 
Clean Code III - Software Craftsmanship at SoCal Code Camp San Diego (07/27/2...
Theo Jungeblut
Ā 
Coding Standard And Code Review
Milan Vukoje
Ā 
Software Development Practices in Practice
Dennis Doomen
Ā 
Clean code and code smells
Md. Aftab Uddin Kajal
Ā 
Ad

More from Nacho Cougil (18)

PPTX
How John started to like TDD (instead of hating it) (ViennaJUG, June'25)
Nacho Cougil
Ā 
PPTX
Slack like a pro: strategies for 10x engineering teams (JCON Europe, May'25)
Nacho Cougil
Ā 
PPTX
How John started to like TDD (instead of hating it) - Talent Arena (March '25)
Nacho Cougil
Ā 
PPTX
How John started to like TDD (instead of hating it)
Nacho Cougil
Ā 
PPTX
All you need is fast feedback loop, fast feedback loop, fast feedback loop is...
Nacho Cougil
Ā 
PPTX
All you need is fast feedback loop, fast feedback loop, fast feedback loop is...
Nacho Cougil
Ā 
PPTX
TDD - Seriously, try it - Codemotion (May '24)
Nacho Cougil
Ā 
PPTX
TDD - Seriously, try it! - Opensouthcode
Nacho Cougil
Ā 
PPTX
TDD - Seriously, try it! - Bucarest Tech Week
Nacho Cougil
Ā 
PPTX
TDD - Seriously, try it! - Trjjmiasto JUG (17th May '23)
Nacho Cougil
Ā 
PPTX
TDD - Seriously, try it! (updated '22)
Nacho Cougil
Ā 
PPTX
Refactor your code: when, why and how (revisited)
Nacho Cougil
Ā 
PPTX
TDD: seriously, try it! 
Nacho Cougil
Ā 
PPTX
Refactor your code: when, why and how?
Nacho Cougil
Ā 
PPTX
Introduction to TDD
Nacho Cougil
Ā 
PPTX
BarcelonaJUG at GDG summit
Nacho Cougil
Ā 
PPT
Gencat Notifier
Nacho Cougil
Ā 
ODP
Seghismed - Disseny i desenvolupament d'un esquema criptogrĆ fic per gestionar...
Nacho Cougil
Ā 
How John started to like TDD (instead of hating it) (ViennaJUG, June'25)
Nacho Cougil
Ā 
Slack like a pro: strategies for 10x engineering teams (JCON Europe, May'25)
Nacho Cougil
Ā 
How John started to like TDD (instead of hating it) - Talent Arena (March '25)
Nacho Cougil
Ā 
How John started to like TDD (instead of hating it)
Nacho Cougil
Ā 
All you need is fast feedback loop, fast feedback loop, fast feedback loop is...
Nacho Cougil
Ā 
All you need is fast feedback loop, fast feedback loop, fast feedback loop is...
Nacho Cougil
Ā 
TDD - Seriously, try it - Codemotion (May '24)
Nacho Cougil
Ā 
TDD - Seriously, try it! - Opensouthcode
Nacho Cougil
Ā 
TDD - Seriously, try it! - Bucarest Tech Week
Nacho Cougil
Ā 
TDD - Seriously, try it! - Trjjmiasto JUG (17th May '23)
Nacho Cougil
Ā 
TDD - Seriously, try it! (updated '22)
Nacho Cougil
Ā 
Refactor your code: when, why and how (revisited)
Nacho Cougil
Ā 
TDD: seriously, try it! 
Nacho Cougil
Ā 
Refactor your code: when, why and how?
Nacho Cougil
Ā 
Introduction to TDD
Nacho Cougil
Ā 
BarcelonaJUG at GDG summit
Nacho Cougil
Ā 
Gencat Notifier
Nacho Cougil
Ā 
Seghismed - Disseny i desenvolupament d'un esquema criptogrĆ fic per gestionar...
Nacho Cougil
Ā 
Ad

Recently uploaded (20)

PDF
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
Ā 
PDF
Google’s NotebookLM Unveils Video Overviews
SOFTTECHHUB
Ā 
PDF
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
Artjoker Software Development Company
Ā 
PDF
This slide provides an overview Technology
mineshkharadi333
Ā 
PPTX
The Power of IoT Sensor Integration in Smart Infrastructure and Automation.pptx
Rejig Digital
Ā 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
Ā 
PPTX
Smart Infrastructure and Automation through IoT Sensors
Rejig Digital
Ā 
PDF
Building High-Performance Oracle Teams: Strategic Staffing for Database Manag...
SMACT Works
Ā 
PDF
agentic-ai-and-the-future-of-autonomous-systems.pdf
siddharthnetsavvies
Ā 
PDF
Doc9.....................................
SofiaCollazos
Ā 
PDF
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
Ā 
PDF
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
Ā 
PDF
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
Ā 
PDF
Shreyas_Phanse_Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
SHREYAS PHANSE
Ā 
PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
Ā 
PDF
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
Ā 
PDF
NewMind AI Monthly Chronicles - July 2025
NewMind AI
Ā 
PDF
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
Ā 
PDF
Revolutionize Operations with Intelligent IoT Monitoring and Control
Rejig Digital
Ā 
PDF
CIFDAQ'S Market Insight: BTC to ETH money in motion
CIFDAQ
Ā 
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
Ā 
Google’s NotebookLM Unveils Video Overviews
SOFTTECHHUB
Ā 
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
Artjoker Software Development Company
Ā 
This slide provides an overview Technology
mineshkharadi333
Ā 
The Power of IoT Sensor Integration in Smart Infrastructure and Automation.pptx
Rejig Digital
Ā 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
Ā 
Smart Infrastructure and Automation through IoT Sensors
Rejig Digital
Ā 
Building High-Performance Oracle Teams: Strategic Staffing for Database Manag...
SMACT Works
Ā 
agentic-ai-and-the-future-of-autonomous-systems.pdf
siddharthnetsavvies
Ā 
Doc9.....................................
SofiaCollazos
Ā 
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
Ā 
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
Ā 
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
Ā 
Shreyas_Phanse_Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
SHREYAS PHANSE
Ā 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
Ā 
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
Ā 
NewMind AI Monthly Chronicles - July 2025
NewMind AI
Ā 
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
Ā 
Revolutionize Operations with Intelligent IoT Monitoring and Control
Rejig Digital
Ā 
CIFDAQ'S Market Insight: BTC to ETH money in motion
CIFDAQ
Ā 

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