SlideShare a Scribd company logo
1 of 84
Download to read offline
Smell your Code!

  Yaser Sulaiman




    www.free-dimension.com   1
These slides are based on an
internal presentation I gave
  @ Free Dimension (FD)




          www.free-dimension.com   2
It contained examples from real
            projects



            www.free-dimension.com   3
FD agreed to publish it online under
     a CC BY-NC-SA license…



              www.free-dimension.com   4
after removing, or disguising, the
         real examples



             www.free-dimension.com   5
Disguised examples are marked
                 with



δ              www.free-dimension.com   6
Our road map




   www.free-dimension.com   7
What?     Why?                   How?




        www.free-dimension.com          8
If you can take away only 1 lesson…




              www.free-dimension.com   9
Don’t Repeat Yourself!




       www.free-dimension.com   10
This rule is so important I have to
              break it



              www.free-dimension.com   11
Don’t Repeat Yourself!




       www.free-dimension.com   12
What?     Why?                   How?




        www.free-dimension.com          13
Code smells?!




   www.free-dimension.com   14
Warning signs




   www.free-dimension.com   15
photo by pj_in_oz
www.free-dimension.com   16
Surface indications of deeper
          problems



           www.free-dimension.com   17
photo by BenChenowethWork
     www.free-dimension.com   18
Surface indications of deeper
          problems



           www.free-dimension.com   19
www.free-dimension.com   20
What?     Why?                   How?




        www.free-dimension.com          21
The bigger picture




     www.free-dimension.com   22
Software
   Quality


  Code Quality




      Code Smells




   not to scale
www.free-dimension.com   23
Writing HQ code should be the
          priority



           www.free-dimension.com   24
www.free-dimension.com   25
www.free-dimension.com   26
One path to cleaner code goes
    through code smells



           www.free-dimension.com   27
What?     Why?                   How?




        www.free-dimension.com          28
Can you smell code?!




      www.free-dimension.com   29
photo by lanceball

www.free-dimension.com   30
There’re many code smells




         www.free-dimension.com   31
The following smells are just a
            subset



            www.free-dimension.com   32
They’re some of the smells I smelled
         while working here



              www.free-dimension.com   33
Code Smell #1




   www.free-dimension.com   34
DupIicated code DupIicated code
DupIicated code DupIicated code
DupIicated code DupIicated code
DupIicated code DupIicated code
DupIicated code DupIicated code
DupIicated code DupIicated code
DupIicated code DupIicated code
DupIicated code DupIicated code
DupIicated code DupIicated code
            www.free-dimension.com   35
The nastiest code smell




        www.free-dimension.com   36
DupIicated code DupIicated code
DupIicated code DupIicated code
DupIicated code DupIicated code
DupIicated code DupIicated code
DupIicated code DupIicated code
DupIicated code DupIicated code
DupIicated code DupIicated code
DupIicated code DupIicated code
DupIicated code DupIicated code
            www.free-dimension.com   37
Example #1




  www.free-dimension.com   38
BooksController
             &
    NotebooksController



δ         www.free-dimension.com   39
The diff test




   www.free-dimension.com   40
FD Employees Only!




    ignoring whitespace differences
           www.free-dimension.com     41
Example #2




  www.free-dimension.com   42
MessagesController




δ         www.free-dimension.com   43
class MessagesController extends AppController {
  function zebra_inbox() {
    // inbox code
  }

    function zebra_view($id = null) {
      // view message code
    }
}




δ                      www.free-dimension.com      44
class MessagesController extends AppController {
  function zebra_inbox() {
    // inbox code
  }

    function elephant_inbox() {
      // inbox code
    }

    function zebra_view($id = null) {
      // view message code
    }

    function elephant_view($id = null) {
      // view message code
    }
}



δ                                 www.free-dimension.com   45
But then came the penguin, the
         dolphin, the chimp,…



δ              www.free-dimension.com   46
Refactor!




 www.free-dimension.com   47
class MessagesController extends AppController {
  function zebra_inbox() {
    $this->setAction('inbox');
  }

 function elephant_inbox() {
   $this->setAction('inbox');
 }

 function inbox() {
   // inbox code
 }

 function zebra_view($id = null) {
   $this->setAction('view', $id);
 }

 function elephant_view($id = null) {
   $this->setAction('view', $id);
 }

 function view($id = null) {
    // view message code
  }
}




δ                                          www.free-dimension.com   48
Added plus: no duplicated views




            www.free-dimension.com   49
FD Employees Only!




      www.free-dimension.com   50
Code Smell #2




   www.free-dimension.com   51
Too many parameters




      www.free-dimension.com   52
How many is too many?




       www.free-dimension.com   53
www.free-dimension.com   54
www.free-dimension.com   55
Example

(brace your noses!)




     www.free-dimension.com   56
public abstract class AProvider
{
  public abstract void AddToFamily(int familyId, string firstName, string sex,
    string photo, DateTime? birthDate, string birthCountry, string birthCity,
    bool living, DateTime? deathDate, string country, string city, string email,
    string homepage, string mobilePhone, string biography, string jobTitle,
    string maritalStatus, string spouse, int order, int? fatherId);

    public abstract void UpdateInFamily(int id, int familyId, string firstName,
      string sex, string photo, DateTime? birthDate, string birthCountry,
      string birthCity, bool living, DateTime? deathDate, string country,
      string city, string email, string homepage, string mobilePhone,
      string biography, string jobTitle, string maritalStatus, string spouse,
      int order, int? fatherId);
}




δ                                  www.free-dimension.com                    57
!




www.free-dimension.com   58
I misunderstood coupling. My bad!




             www.free-dimension.com   59
public abstract class AProvider
{
  public abstract void AddToFamily(Person person);

    public abstract void UpdateInFamily(Person person);
}




δ                        www.free-dimension.com           60
The remaining smells have many
 examples; check the repository



            www.free-dimension.com   61
Code Smell #3




   www.free-dimension.com   62
Not following a coding
convention/standard/style
       consistently



         www.free-dimension.com   63
Not following a coding
convention/standard/style
       consistently



         www.free-dimension.com   64
The specifics doesn’t really matter;
 what matters most is consistency



              www.free-dimension.com   65
Code Smell #4




   www.free-dimension.com   66
// code.CommentOut();




       www.free-dimension.com   67
“Commented-out code is an
abomination.”—Uncle Bob
     photo used with permission of Uncle Bob
                www.free-dimension.com         68
Don’t commit commented-out code




            www.free-dimension.com   69
Code Smell #5




   www.free-dimension.com   70
redundant

// This is a comment




       www.free-dimension.com   71
Comments
should focus on



            What?                  Why?   How?




          www.free-dimension.com                 72
What?     Why?                   How?




        www.free-dimension.com          73
I may have come off as an a$$




           www.free-dimension.com   74
My code smells as bad as everyone
 else’s.. sometimes even worse



             www.free-dimension.com   75
But I’m aware of my smells




         www.free-dimension.com   76
I try my best to prevent them




           www.free-dimension.com   77
I don’t ignore them; I deal with
             them



            www.free-dimension.com   78
I smell my code




    www.free-dimension.com   79
You should smell your code too




           www.free-dimension.com   80
If you want to sniff more…




         www.free-dimension.com   81
more than just code smells
    www.free-dimension.com   82
…</presentation>
  <questions>…



     www.free-dimension.com   83
www.free-dimension.com   84

More Related Content

Similar to Smell your Code! @ Free Dimension

Writing clean code in C# and .NET
Writing clean code in C# and .NETWriting clean code in C# and .NET
Writing clean code in C# and .NETDror Helper
 
Clean Code - The Next Chapter
Clean Code - The Next ChapterClean Code - The Next Chapter
Clean Code - The Next ChapterVictor Rentea
 
Code Excellence for the Average Programmer
Code Excellence for the Average ProgrammerCode Excellence for the Average Programmer
Code Excellence for the Average ProgrammerLlewellyn Falco
 
Smell your Code! @ IET-KFUPM PATW
Smell your Code! @ IET-KFUPM PATWSmell your Code! @ IET-KFUPM PATW
Smell your Code! @ IET-KFUPM PATWYaser Sulaiman
 
Coding Dojo (November, 2017)
Coding Dojo (November, 2017)Coding Dojo (November, 2017)
Coding Dojo (November, 2017)Rachel M. Carmena
 
Death of a Themer - Frontend United - 14 April 2013
Death of a Themer - Frontend United - 14 April 2013Death of a Themer - Frontend United - 14 April 2013
Death of a Themer - Frontend United - 14 April 2013Matt Fielding
 
DDD beyond the infamous repository pattern - GeeCon Prague 2018
DDD beyond the infamous repository pattern - GeeCon Prague 2018DDD beyond the infamous repository pattern - GeeCon Prague 2018
DDD beyond the infamous repository pattern - GeeCon Prague 2018Cyrille Martraire
 
Monitoring a program that monitors computer networks
Monitoring a program that monitors computer networksMonitoring a program that monitors computer networks
Monitoring a program that monitors computer networksPVS-Studio
 
Clean Code @Voxxed Days Cluj 2023 - opening Keynote
Clean Code @Voxxed Days Cluj 2023 - opening KeynoteClean Code @Voxxed Days Cluj 2023 - opening Keynote
Clean Code @Voxxed Days Cluj 2023 - opening KeynoteVictor Rentea
 
Efficient JavaScript Development
Efficient JavaScript DevelopmentEfficient JavaScript Development
Efficient JavaScript Developmentwolframkriesing
 
Refactoring 2TheMax (con ReSharper)
Refactoring 2TheMax (con ReSharper)Refactoring 2TheMax (con ReSharper)
Refactoring 2TheMax (con ReSharper)DotNetMarche
 
Handle your Lambdas - From event-based processing to Continuous Integration /...
Handle your Lambdas - From event-based processing to Continuous Integration /...Handle your Lambdas - From event-based processing to Continuous Integration /...
Handle your Lambdas - From event-based processing to Continuous Integration /...Sergii Khomenko
 
Efficient JavaScript Development
Efficient JavaScript DevelopmentEfficient JavaScript Development
Efficient JavaScript Developmentwolframkriesing
 
Effective Code Reviews
Effective Code ReviewsEffective Code Reviews
Effective Code ReviewsFrank Sons
 
Tetuan Valley Startup School presentation
Tetuan Valley Startup School presentationTetuan Valley Startup School presentation
Tetuan Valley Startup School presentationKubide
 

Similar to Smell your Code! @ Free Dimension (20)

Writing clean code in C# and .NET
Writing clean code in C# and .NETWriting clean code in C# and .NET
Writing clean code in C# and .NET
 
Clean Code - The Next Chapter
Clean Code - The Next ChapterClean Code - The Next Chapter
Clean Code - The Next Chapter
 
Code Excellence for the Average Programmer
Code Excellence for the Average ProgrammerCode Excellence for the Average Programmer
Code Excellence for the Average Programmer
 
Smell your Code! @ IET-KFUPM PATW
Smell your Code! @ IET-KFUPM PATWSmell your Code! @ IET-KFUPM PATW
Smell your Code! @ IET-KFUPM PATW
 
Coding Dojo (November, 2017)
Coding Dojo (November, 2017)Coding Dojo (November, 2017)
Coding Dojo (November, 2017)
 
Death of a Themer - Frontend United - 14 April 2013
Death of a Themer - Frontend United - 14 April 2013Death of a Themer - Frontend United - 14 April 2013
Death of a Themer - Frontend United - 14 April 2013
 
DDD beyond the infamous repository pattern - GeeCon Prague 2018
DDD beyond the infamous repository pattern - GeeCon Prague 2018DDD beyond the infamous repository pattern - GeeCon Prague 2018
DDD beyond the infamous repository pattern - GeeCon Prague 2018
 
Monitoring a program that monitors computer networks
Monitoring a program that monitors computer networksMonitoring a program that monitors computer networks
Monitoring a program that monitors computer networks
 
Clean Code @Voxxed Days Cluj 2023 - opening Keynote
Clean Code @Voxxed Days Cluj 2023 - opening KeynoteClean Code @Voxxed Days Cluj 2023 - opening Keynote
Clean Code @Voxxed Days Cluj 2023 - opening Keynote
 
DDD for real
DDD for realDDD for real
DDD for real
 
Efficient JavaScript Development
Efficient JavaScript DevelopmentEfficient JavaScript Development
Efficient JavaScript Development
 
Wtf per lineofcode
Wtf per lineofcodeWtf per lineofcode
Wtf per lineofcode
 
Refactoring 2TheMax (con ReSharper)
Refactoring 2TheMax (con ReSharper)Refactoring 2TheMax (con ReSharper)
Refactoring 2TheMax (con ReSharper)
 
Handle your Lambdas - From event-based processing to Continuous Integration /...
Handle your Lambdas - From event-based processing to Continuous Integration /...Handle your Lambdas - From event-based processing to Continuous Integration /...
Handle your Lambdas - From event-based processing to Continuous Integration /...
 
Efficient JavaScript Development
Efficient JavaScript DevelopmentEfficient JavaScript Development
Efficient JavaScript Development
 
Roboform Basic Tutorial
Roboform Basic TutorialRoboform Basic Tutorial
Roboform Basic Tutorial
 
Effective Code Reviews
Effective Code ReviewsEffective Code Reviews
Effective Code Reviews
 
Tetuan Valley Startup School presentation
Tetuan Valley Startup School presentationTetuan Valley Startup School presentation
Tetuan Valley Startup School presentation
 
Tetuan Valley Startup School Presentation
Tetuan Valley Startup School PresentationTetuan Valley Startup School Presentation
Tetuan Valley Startup School Presentation
 
Sylius, the good choice
Sylius, the good choiceSylius, the good choice
Sylius, the good choice
 

Recently uploaded

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
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
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
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
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
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdfChristopherTHyatt
 
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
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 

Recently uploaded (20)

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
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
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
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
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
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
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
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 

Smell your Code! @ Free Dimension