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

Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
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
 
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
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
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
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
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
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
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
 

Recently uploaded (20)

Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
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
 
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
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
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
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
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
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
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
 

Smell your Code! @ Free Dimension