SlideShare une entreprise Scribd logo
1  sur  54
Bay.NET
                 San Francisco


Clean Code
 Design Patterns
and Best Practices
  San Francisco, January 16th 2013
Theo Jungeblut
• Engineering manager & lead by day
  at AppDynamics in San Francisco

• Coder & software craftsman by night

• Architects decoupled solutions
  tailored to business needs & crafts
  maintainable code to last
• Worked in healthcare and factory
  automation, building mission critical
  applications, framework & platforms
• Degree in Software Engineering
  and Network Communications
                                          theo@designitright.net
• Enjoys cycling, running and eating
                                          www.designitright.net
Rate Session & Win a Shirt




http://www.speakerrate.com/theoj
Where to get the Slides




http://www.slideshare.net/theojungeblut
Overview
•   Why Clean Code
•   Clean Code Developer Initiative
•   Principles and Practices
•   Code Comparison
•   Q&A
Does writing Clean Code
make us more efficient?
The only valid Measurement of Code
               Quality
What is Clean Code?
Clean Code is maintainable

     Source code must be:
     • readable & well structured
     • extensible
     • testable
Software
 Engineering
       &
   Software
Craftsmanship
The “Must Read”-Book(s)
 by Robert C Martin


A Handbook of Agile
Software
Craftsmanship

“Even bad code can
function. But if code
isn’t clean, it can bring a
development
organization to its
knees.”
Code Maintainability *
    Principles                   Patterns                   Containers


       Why?                        How?                        What?


  Extensibility                Clean Code                   Tool reuse

* from: Mark Seemann’s “Dependency Injection in .NET” presentation Bay.NET 05/2011
Clean Code Developer




Graphic by Michael Hönnig http://michael.hoennig.de/2009/08/08/clean-code-developer-ccd/
Clean Code Developer – 1st Iteration
     by Ralf Westphal & Stefan Lieser – http://www.clean-code-developer.de




Graphic by Michael Hönnig http://michael.hoennig.de/2009/08/08/clean-code-developer-ccd/
Keep it simple, stupid
        (KISS)
KISS-Principle – “Keep It Simple Stupid”
   by Kelly Johnson




                      http://blogs.smarter.com/blogs/Lego%20Brick.jpg
The Power of Simplicity




                                                       Graphic by Nathan Sawaya courtesy of brickartist.com




Graphic by Nathan Sawaya courtesy of brickartist.com

                                                                                http://www.geekalerts.com/lego-iphone/
Chaos build from simplicity




Graphic by Nathan Sawaya courtesy of brickartist.com
Don’t repeat yourself
        (DRY)
Don’t repeat yourself (DRY)
        by Andy Hunt and Dave Thomas in their book “The Pragmatic Programmer”

// Code Copy and Paste Method                                                    // DRY Method
public Class Person                                                              public Class Person
 {                                                                                {
   public string FirstName { get; set;}                                             public string FirstName { get; set;}
   public string LastName { get; set;}                                              public string LastName { get; set;}

    public Person(Person person)                                                     public Person(Person person)
    {                                                                                {
      this.FirstName = string.IsNullOrEmpty(person.FirstName)                          this.FirstName = person.FirstName.CloneSecured();
                 ? string.Empty : (string) person.FirstName.Clone();                   this.LastName = person.LastName.CloneSecured();
                                                                                     }
        this.LastName = string.IsNullOrEmpty(person.LastName)
                  ? string.Empty : (string) person.LastName.Clone();                 public object Clone()
    }                                                                                {
                                                                                       return new Person(this);
    public object Clone()                                                            }
    {                                                                            }
      return new Person(this);
    }
}                                         public static class StringExtension
                                           {
                                             public static string CloneSecured(this string original)
                                             {
                                               return string.IsNullOrEmpty(original) ? string.Empty : (string)original.Clone();
                                             }
                                          }
Clean Code Developer – 1st Iteration
     by Ralf Westphal & Stefan Lieser – http://www.clean-code-developer.de




Graphic by Michael Hönnig http://michael.hoennig.de/2009/08/08/clean-code-developer-ccd/
Clean Code Developer – 2nd Iteration
     by Ralf Westphal & Stefan Lieser – http://www.clean-code-developer.de




Graphic by Michael Hönnig http://michael.hoennig.de/2009/08/08/clean-code-developer-ccd/
Separation of Concerns
         (SoC)

 Single Responsibility
       Principle
         (SRP)
The Product




http://www.technicopedia.com/8865.html
Component / Service




          http://www.technicopedia.com/8865.html
Class, Struct, Enum etc.




http://technicbricks.blogspot.com/2009/06/tbs-techpoll-12-results-2009-1st.html
Separation of Concerns (SoC)
     probably by Edsger W. Dijkstra in 1974

• “In computer
science, separation of concerns
(SoC) is the process of separating
a computer program into distinct
features that overlap in
functionality as little as possible.

•A concern is any piece of
interest or focus in a program.
Typically, concerns are
synonymous with features or
behaviors. “
 http://en.wikipedia.org/wiki/Separati
 on_of_Concerns
Single Responsibility Principle (SRP)
      by Robert C Martin


“Every object should have a single responsibility, and that
responsibility should be entirely encapsulated by the class.”
    http://en.wikipedia.org/wiki/Single_responsibility_principle




public class Logger : ILogger
{
  public Logger(ILoggingSink loggingSink)
  {}

     public void Log(string message)
     {}
}
                                                                   http://www.ericalbrecht.com
Read, Read, Read
Clean Code Developer – 2nd Iteration
     by Ralf Westphal & Stefan Lieser – http://www.clean-code-developer.de




Graphic by Michael Hönnig http://michael.hoennig.de/2009/08/08/clean-code-developer-ccd/
Clean Code Developer – 3rd Iteration
     by Ralf Westphal & Stefan Lieser – http://www.clean-code-developer.de




Graphic by Michael Hönnig http://michael.hoennig.de/2009/08/08/clean-code-developer-ccd/
Information Hiding Principle
           (IHP)
Information Hiding Principle (IHP)
         by David Parnas (1972)


“.. information hiding is the principle of
segregation of the design decisions on a
computer program that are most likely to
change, ..”
 http://en.wikipedia.org/wiki/Information_hiding
Interfaces / Contracts
• Decouple Usage and Implementation through introduction of a contract
• Allows to replace implementation without changing the consumer

public interface ILogger              public class Logger : ILogger
{                                     {
  void Log(string message);             public Logger(ILoggingSink loggingSink)
}                                       {}

                                          public void Log(string message)
                                          {}
                                      }
Liskov Substitution Principle
           (LSP)
Liskov Substitution Principle (LSP)
by Barbara Liskov, Jannette Wing (1994)


“Liskov’s notion of a behavioral subtype
defines a notion of substitutability for
mutable objects”
 http://en.wikipedia.org/wiki/Liskov_substitution_principle
Dependency Inversion Principle
           (DIP)
Dependency Inversion Principle (DIP)
  by Robert C. Martin


• “High-level modules should not depend on
  low-level modules. Both should depend on
  abstractions.
• Abstractions should not depend upon details.
  Details should depend upon abstractions.”
  http://en.wikipedia.org/wiki/Dependency_inversion_principle
Silicon Valley Code Camp Oct. ~ 5th – 6th




http://www.siliconvalley-codecamp.com
Clean Code Developer – 3rd Iteration
     by Ralf Westphal & Stefan Lieser – http://www.clean-code-developer.de




Graphic by Michael Hönnig http://michael.hoennig.de/2009/08/08/clean-code-developer-ccd/
Clean Code Developer – 4th Iteration
     by Ralf Westphal & Stefan Lieser – http://www.clean-code-developer.de




Graphic by Michael Hönnig http://michael.hoennig.de/2009/08/08/clean-code-developer-ccd/
Open Closed Principle
       (OCP)
Open/Closed Principle (OCP)
by Bertrand Meyer (1988)


An implementation is open for extension
but closed for modification




           http://en.wikipedia.org/wiki/Open/closed_principle
Law of Demeter
     (LoD)
Law of Demeter (LoD)
           Northeastern University (1987)

“
• 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.”
  http://en.wikipedia.org/wiki/Law_Of_Demeter
S               Single Responsibility Principle

   O               Open/Closed Principle

   L               Liskov Substitution Principle

   I               Interface Segregation Principle

   D               Dependency Inversion Principle

Robert C Martin:   http://butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod
Clean Code Developer – 4th Iteration
     by Ralf Westphal & Stefan Lieser – http://www.clean-code-developer.de




Graphic by Michael Hönnig http://michael.hoennig.de/2009/08/08/clean-code-developer-ccd/
Clean Code Developer – 5th Iteration
     by Ralf Westphal & Stefan Lieser – http://www.clean-code-developer.de




Graphic by Michael Hönnig http://michael.hoennig.de/2009/08/08/clean-code-developer-ccd/
Summary Clean Code
Maintainability is achieved through:
• Readability (Coding Guidelines)
• Simplification and Specialization
  (KISS, SoC, SRP, OCP, )
• Decoupling (LSP, DIP, IHP, Contracts,
  LoD, CoP, IoC or SOA)
• Avoiding Code Bloat (DRY, YAGNI)
• Quality through Testability
  (all of them!)
Q&A
                                         Downloads,
                                         Feedback & Comments:
                                                   theo@designitright.net
                                                   www.designitright.net
                                                   www.speakerrate.com/theoj
Graphic by Nathan Sawaya courtesy of brickartist.com
http://clean-code-developer.com
                                          References…
http://michael.hoennig.de/2009/08/08/clean-code-developer-ccd/
http://butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod
http://www.manning.com/seemann/
http://en.wikipedia.org/wiki/Keep_it_simple_stupid
http://picocontainer.org/patterns.html
http://en.wikipedia.org/wiki/Separation_of_concerns
http://en.wikipedia.org/wiki/Single_responsibility_principle
http://en.wikipedia.org/wiki/Information_hiding
http://en.wikipedia.org/wiki/Liskov_substitution_principle
http://en.wikipedia.org/wiki/Dependency_inversion_principle
http://en.wikipedia.org/wiki/Open/closed_principle
http://en.wikipedia.org/wiki/Law_Of_Demeter
http://en.wikipedia.org/wiki/Don't_repeat_yourself
http://en.wikipedia.org/wiki/You_ain't_gonna_need_it
http://en.wikipedia.org/wiki/Component-oriented_programming
http://en.wikipedia.org/wiki/Service-oriented_architecture
http://www.martinfowler.com/articles/injection.html
http://www.codeproject.com/KB/aspnet/IOCDI.aspx
http://msdn.microsoft.com/en-us/magazine/cc163739.aspx
http://msdn.microsoft.com/en-us/library/ff650320.aspx
http://msdn.microsoft.com/en-us/library/aa973811.aspx
http://msdn.microsoft.com/en-us/library/ff647976.aspx
http://msdn.microsoft.com/en-us/library/cc707845.aspx
http://msdn.microsoft.com/en-us/library/bb833022.aspx
http://unity.codeplex.com/
http://www.idesign.net/idesign/DesktopDefault.aspx?tabindex=5&tabid=11
… more References
Resharper
http://www.jetbrains.com/resharper/

FxCop / Code Analysis
http://msdn.microsoft.com/en-us/library/bb429476(VS.80).aspx
http://blogs.msdn.com/b/codeanalysis/
http://www.binarycoder.net/fxcop/index.html

Code Contracts
http://msdn.microsoft.com/en-us/devlabs/dd491992
http://research.microsoft.com/en-us/projects/contracts/

Pex & Mole
http://research.microsoft.com/en-us/projects/pex/

StyleCop
http://stylecop.codeplex.com/

Ghostdoc
http://submain.com/products/ghostdoc.aspx

Spellchecker
http://visualstudiogallery.msdn.microsoft.com/
7c8341f1-ebac-40c8-92c2-476db8d523ce//
                                                               Lego (trademarked in capitals as LEGO)
Blog, Rating, Slides


www.speakerrate.com/theoj




www.slideshare.net/theojungeblut



             http://www.DesignItRight.net
Please fill out the
feedback, and…


… thanks for you attention!

Contenu connexe

Tendances

Contract First Development with Microsoft Code Contracts and Microsoft Pex at...
Contract First Development with Microsoft Code Contracts and Microsoft Pex at...Contract First Development with Microsoft Code Contracts and Microsoft Pex at...
Contract First Development with Microsoft Code Contracts and Microsoft Pex at...Theo Jungeblut
 
Clean Code I - Best Practices
Clean Code I - Best PracticesClean Code I - Best Practices
Clean Code I - Best PracticesTheo Jungeblut
 
Clean Code Part i - Design Patterns and Best Practices -
Clean Code Part i - Design Patterns and Best Practices -Clean Code Part i - Design Patterns and Best Practices -
Clean Code Part i - Design Patterns and Best Practices -Theo Jungeblut
 
Clean Code I - Design Patterns and Best Practices at SoCal Code Camp San Dieg...
Clean Code I - Design Patterns and Best Practices at SoCal Code Camp San Dieg...Clean Code I - Design Patterns and Best Practices at SoCal Code Camp San Dieg...
Clean Code I - Design Patterns and Best Practices at SoCal Code Camp San Dieg...Theo Jungeblut
 
Lego For Engineers - Dependency Injection for LIDNUG (2011-06-03)
Lego For Engineers - Dependency Injection for LIDNUG (2011-06-03)Lego For Engineers - Dependency Injection for LIDNUG (2011-06-03)
Lego For Engineers - Dependency Injection for LIDNUG (2011-06-03)Theo Jungeblut
 
Lego for Software Engineers at Silicon Valley Code Camp 2011 (2010-10-10)
Lego for Software Engineers at Silicon Valley Code Camp 2011 (2010-10-10)Lego for Software Engineers at Silicon Valley Code Camp 2011 (2010-10-10)
Lego for Software Engineers at Silicon Valley Code Camp 2011 (2010-10-10)Theo Jungeblut
 
Mental models, complexity and software
Mental models, complexity and softwareMental models, complexity and software
Mental models, complexity and softwareArturo Herrero
 
Clean Code III - Software Craftsmanship
Clean Code III - Software CraftsmanshipClean Code III - Software Craftsmanship
Clean Code III - Software CraftsmanshipTheo Jungeblut
 
Tdd is not about testing (OOP)
Tdd is not about testing (OOP)Tdd is not about testing (OOP)
Tdd is not about testing (OOP)Gianluca Padovani
 
Tdd is not about testing (C++ version)
Tdd is not about testing (C++ version)Tdd is not about testing (C++ version)
Tdd is not about testing (C++ version)Gianluca Padovani
 
Clean code & design patterns
Clean code & design patternsClean code & design patterns
Clean code & design patternsPascal Larocque
 
WordCamp US: Clean Code
WordCamp US: Clean CodeWordCamp US: Clean Code
WordCamp US: Clean Codemtoppa
 
Functional Dependency Injection in C#
Functional Dependency Injection in C#Functional Dependency Injection in C#
Functional Dependency Injection in C#Thomas Jaskula
 
Cut your Dependencies with Dependency Injection - .NET User Group Osnabrueck
Cut your Dependencies with Dependency Injection - .NET User Group OsnabrueckCut your Dependencies with Dependency Injection - .NET User Group Osnabrueck
Cut your Dependencies with Dependency Injection - .NET User Group OsnabrueckTheo Jungeblut
 
Cut your Dependencies - Dependency Injection at Silicon Valley Code Camp
Cut your Dependencies - Dependency Injection at Silicon Valley Code CampCut your Dependencies - Dependency Injection at Silicon Valley Code Camp
Cut your Dependencies - Dependency Injection at Silicon Valley Code CampTheo Jungeblut
 

Tendances (20)

Contract First Development with Microsoft Code Contracts and Microsoft Pex at...
Contract First Development with Microsoft Code Contracts and Microsoft Pex at...Contract First Development with Microsoft Code Contracts and Microsoft Pex at...
Contract First Development with Microsoft Code Contracts and Microsoft Pex at...
 
Clean Code I - Best Practices
Clean Code I - Best PracticesClean Code I - Best Practices
Clean Code I - Best Practices
 
Clean Code Part i - Design Patterns and Best Practices -
Clean Code Part i - Design Patterns and Best Practices -Clean Code Part i - Design Patterns and Best Practices -
Clean Code Part i - Design Patterns and Best Practices -
 
Clean Code I - Design Patterns and Best Practices at SoCal Code Camp San Dieg...
Clean Code I - Design Patterns and Best Practices at SoCal Code Camp San Dieg...Clean Code I - Design Patterns and Best Practices at SoCal Code Camp San Dieg...
Clean Code I - Design Patterns and Best Practices at SoCal Code Camp San Dieg...
 
Lego For Engineers - Dependency Injection for LIDNUG (2011-06-03)
Lego For Engineers - Dependency Injection for LIDNUG (2011-06-03)Lego For Engineers - Dependency Injection for LIDNUG (2011-06-03)
Lego For Engineers - Dependency Injection for LIDNUG (2011-06-03)
 
Clean code
Clean codeClean code
Clean code
 
Lego for Software Engineers at Silicon Valley Code Camp 2011 (2010-10-10)
Lego for Software Engineers at Silicon Valley Code Camp 2011 (2010-10-10)Lego for Software Engineers at Silicon Valley Code Camp 2011 (2010-10-10)
Lego for Software Engineers at Silicon Valley Code Camp 2011 (2010-10-10)
 
Clean Code 2
Clean Code 2Clean Code 2
Clean Code 2
 
Mental models, complexity and software
Mental models, complexity and softwareMental models, complexity and software
Mental models, complexity and software
 
Clean Code III - Software Craftsmanship
Clean Code III - Software CraftsmanshipClean Code III - Software Craftsmanship
Clean Code III - Software Craftsmanship
 
Tdd is not about testing (OOP)
Tdd is not about testing (OOP)Tdd is not about testing (OOP)
Tdd is not about testing (OOP)
 
Tdd is not about testing (C++ version)
Tdd is not about testing (C++ version)Tdd is not about testing (C++ version)
Tdd is not about testing (C++ version)
 
Clean code & design patterns
Clean code & design patternsClean code & design patterns
Clean code & design patterns
 
Dependency Injection
Dependency InjectionDependency Injection
Dependency Injection
 
SOLID design principles applied in Java
SOLID design principles applied in JavaSOLID design principles applied in Java
SOLID design principles applied in Java
 
WordCamp US: Clean Code
WordCamp US: Clean CodeWordCamp US: Clean Code
WordCamp US: Clean Code
 
Binding android piece by piece
Binding android piece by pieceBinding android piece by piece
Binding android piece by piece
 
Functional Dependency Injection in C#
Functional Dependency Injection in C#Functional Dependency Injection in C#
Functional Dependency Injection in C#
 
Cut your Dependencies with Dependency Injection - .NET User Group Osnabrueck
Cut your Dependencies with Dependency Injection - .NET User Group OsnabrueckCut your Dependencies with Dependency Injection - .NET User Group Osnabrueck
Cut your Dependencies with Dependency Injection - .NET User Group Osnabrueck
 
Cut your Dependencies - Dependency Injection at Silicon Valley Code Camp
Cut your Dependencies - Dependency Injection at Silicon Valley Code CampCut your Dependencies - Dependency Injection at Silicon Valley Code Camp
Cut your Dependencies - Dependency Injection at Silicon Valley Code Camp
 

En vedette

MICHE @www.amelia.miche.com
MICHE @www.amelia.miche.comMICHE @www.amelia.miche.com
MICHE @www.amelia.miche.comAmelia Wood
 
Debugging,Troubleshooting & Monitoring Distributed Web & Cloud Applications a...
Debugging,Troubleshooting & Monitoring Distributed Web & Cloud Applications a...Debugging,Troubleshooting & Monitoring Distributed Web & Cloud Applications a...
Debugging,Troubleshooting & Monitoring Distributed Web & Cloud Applications a...Theo Jungeblut
 
Cut your Dependencies with Dependency Injection for East Bay.NET User Group
Cut your Dependencies with Dependency Injection for East Bay.NET User Group Cut your Dependencies with Dependency Injection for East Bay.NET User Group
Cut your Dependencies with Dependency Injection for East Bay.NET User Group Theo Jungeblut
 
A.Wood.EAF563.PesidentialSalaries
A.Wood.EAF563.PesidentialSalariesA.Wood.EAF563.PesidentialSalaries
A.Wood.EAF563.PesidentialSalariesAmelia Wood
 
Debugging,Troubleshooting & Monitoring Distributed Web & Cloud Applications a...
Debugging,Troubleshooting & Monitoring Distributed Web & Cloud Applications a...Debugging,Troubleshooting & Monitoring Distributed Web & Cloud Applications a...
Debugging,Troubleshooting & Monitoring Distributed Web & Cloud Applications a...Theo Jungeblut
 
Metode ilmiah
Metode ilmiahMetode ilmiah
Metode ilmiahrasyidiq
 
Accidentally Manager – A Survival Guide for First-Time Engineering Managers
Accidentally Manager – A Survival Guide for First-Time Engineering ManagersAccidentally Manager – A Survival Guide for First-Time Engineering Managers
Accidentally Manager – A Survival Guide for First-Time Engineering ManagersTheo Jungeblut
 

En vedette (8)

MICHE @www.amelia.miche.com
MICHE @www.amelia.miche.comMICHE @www.amelia.miche.com
MICHE @www.amelia.miche.com
 
Debugging,Troubleshooting & Monitoring Distributed Web & Cloud Applications a...
Debugging,Troubleshooting & Monitoring Distributed Web & Cloud Applications a...Debugging,Troubleshooting & Monitoring Distributed Web & Cloud Applications a...
Debugging,Troubleshooting & Monitoring Distributed Web & Cloud Applications a...
 
Cut your Dependencies with Dependency Injection for East Bay.NET User Group
Cut your Dependencies with Dependency Injection for East Bay.NET User Group Cut your Dependencies with Dependency Injection for East Bay.NET User Group
Cut your Dependencies with Dependency Injection for East Bay.NET User Group
 
A.Wood.EAF563.PesidentialSalaries
A.Wood.EAF563.PesidentialSalariesA.Wood.EAF563.PesidentialSalaries
A.Wood.EAF563.PesidentialSalaries
 
I verbi composti
I verbi compostiI verbi composti
I verbi composti
 
Debugging,Troubleshooting & Monitoring Distributed Web & Cloud Applications a...
Debugging,Troubleshooting & Monitoring Distributed Web & Cloud Applications a...Debugging,Troubleshooting & Monitoring Distributed Web & Cloud Applications a...
Debugging,Troubleshooting & Monitoring Distributed Web & Cloud Applications a...
 
Metode ilmiah
Metode ilmiahMetode ilmiah
Metode ilmiah
 
Accidentally Manager – A Survival Guide for First-Time Engineering Managers
Accidentally Manager – A Survival Guide for First-Time Engineering ManagersAccidentally Manager – A Survival Guide for First-Time Engineering Managers
Accidentally Manager – A Survival Guide for First-Time Engineering Managers
 

Similaire à Clean Code - Design Patterns and Best Practices for Bay.NET SF User Group (01/16/2013)

designpatterns_blair_upe.ppt
designpatterns_blair_upe.pptdesignpatterns_blair_upe.ppt
designpatterns_blair_upe.pptbanti43
 
Microservices Application Tracing Standards and Simulators - Adrians at OSCON
Microservices Application Tracing Standards and Simulators - Adrians at OSCONMicroservices Application Tracing Standards and Simulators - Adrians at OSCON
Microservices Application Tracing Standards and Simulators - Adrians at OSCONAdrian Cockcroft
 
Seven Ineffective Coding Habits of Many Programmers
Seven Ineffective Coding Habits of Many ProgrammersSeven Ineffective Coding Habits of Many Programmers
Seven Ineffective Coding Habits of Many ProgrammersKevlin Henney
 
2009 Dotnet Information Day: More effective c#
2009 Dotnet Information Day: More effective c#2009 Dotnet Information Day: More effective c#
2009 Dotnet Information Day: More effective c#Daniel Fisher
 
Design patterns in javascript
Design patterns in javascriptDesign patterns in javascript
Design patterns in javascriptAyush Sharma
 
SCAM 2012 Keynote Slides on Cooperative Testing and Analysis by Tao Xie
SCAM 2012 Keynote Slides on Cooperative Testing and Analysis by Tao XieSCAM 2012 Keynote Slides on Cooperative Testing and Analysis by Tao Xie
SCAM 2012 Keynote Slides on Cooperative Testing and Analysis by Tao XieTao Xie
 
1. Mini seminar intro
1. Mini seminar intro1. Mini seminar intro
1. Mini seminar introLeonid Maslov
 
The Ring programming language version 1.8 book - Part 92 of 202
The Ring programming language version 1.8 book - Part 92 of 202The Ring programming language version 1.8 book - Part 92 of 202
The Ring programming language version 1.8 book - Part 92 of 202Mahmoud Samir Fayed
 
Lies Told By The Kotlin Compiler
Lies Told By The Kotlin CompilerLies Told By The Kotlin Compiler
Lies Told By The Kotlin CompilerGarth Gilmour
 
Practical Chaos Engineering
Practical Chaos EngineeringPractical Chaos Engineering
Practical Chaos EngineeringSIGHUP
 
Automated Discovery of Deserialization Gadget Chains
 Automated Discovery of Deserialization Gadget Chains Automated Discovery of Deserialization Gadget Chains
Automated Discovery of Deserialization Gadget ChainsPriyanka Aash
 
Patterns for the People
Patterns for the PeoplePatterns for the People
Patterns for the PeopleKevlin Henney
 
Interop - Crash Course In Open Source Cloud Computing
Interop - Crash Course In Open Source Cloud ComputingInterop - Crash Course In Open Source Cloud Computing
Interop - Crash Course In Open Source Cloud ComputingMark Hinkle
 
Great Wide Open: Crash Course Open Source Cloud Computing - 2014
Great Wide Open: Crash Course Open Source Cloud Computing - 2014Great Wide Open: Crash Course Open Source Cloud Computing - 2014
Great Wide Open: Crash Course Open Source Cloud Computing - 2014Mark Hinkle
 
Framework engineering JCO 2011
Framework engineering JCO 2011Framework engineering JCO 2011
Framework engineering JCO 2011YoungSu Son
 
The software design principles
The software design principlesThe software design principles
The software design principlesAman Kesarwani
 
C# .NET: Language Features and Creating .NET Projects, Namespaces Classes and...
C# .NET: Language Features and Creating .NET Projects, Namespaces Classes and...C# .NET: Language Features and Creating .NET Projects, Namespaces Classes and...
C# .NET: Language Features and Creating .NET Projects, Namespaces Classes and...yazad dumasia
 

Similaire à Clean Code - Design Patterns and Best Practices for Bay.NET SF User Group (01/16/2013) (20)

designpatterns_blair_upe.ppt
designpatterns_blair_upe.pptdesignpatterns_blair_upe.ppt
designpatterns_blair_upe.ppt
 
Microservices Application Tracing Standards and Simulators - Adrians at OSCON
Microservices Application Tracing Standards and Simulators - Adrians at OSCONMicroservices Application Tracing Standards and Simulators - Adrians at OSCON
Microservices Application Tracing Standards and Simulators - Adrians at OSCON
 
Seven Ineffective Coding Habits of Many Programmers
Seven Ineffective Coding Habits of Many ProgrammersSeven Ineffective Coding Habits of Many Programmers
Seven Ineffective Coding Habits of Many Programmers
 
2009 Dotnet Information Day: More effective c#
2009 Dotnet Information Day: More effective c#2009 Dotnet Information Day: More effective c#
2009 Dotnet Information Day: More effective c#
 
Design patterns in javascript
Design patterns in javascriptDesign patterns in javascript
Design patterns in javascript
 
SCAM 2012 Keynote Slides on Cooperative Testing and Analysis by Tao Xie
SCAM 2012 Keynote Slides on Cooperative Testing and Analysis by Tao XieSCAM 2012 Keynote Slides on Cooperative Testing and Analysis by Tao Xie
SCAM 2012 Keynote Slides on Cooperative Testing and Analysis by Tao Xie
 
1. Mini seminar intro
1. Mini seminar intro1. Mini seminar intro
1. Mini seminar intro
 
Object-oriented Basics
Object-oriented BasicsObject-oriented Basics
Object-oriented Basics
 
The Ring programming language version 1.8 book - Part 92 of 202
The Ring programming language version 1.8 book - Part 92 of 202The Ring programming language version 1.8 book - Part 92 of 202
The Ring programming language version 1.8 book - Part 92 of 202
 
Lies Told By The Kotlin Compiler
Lies Told By The Kotlin CompilerLies Told By The Kotlin Compiler
Lies Told By The Kotlin Compiler
 
Practical Chaos Engineering
Practical Chaos EngineeringPractical Chaos Engineering
Practical Chaos Engineering
 
Twins: OOP and FP
Twins: OOP and FPTwins: OOP and FP
Twins: OOP and FP
 
Automated Discovery of Deserialization Gadget Chains
 Automated Discovery of Deserialization Gadget Chains Automated Discovery of Deserialization Gadget Chains
Automated Discovery of Deserialization Gadget Chains
 
Patterns for the People
Patterns for the PeoplePatterns for the People
Patterns for the People
 
Objective c
Objective cObjective c
Objective c
 
Interop - Crash Course In Open Source Cloud Computing
Interop - Crash Course In Open Source Cloud ComputingInterop - Crash Course In Open Source Cloud Computing
Interop - Crash Course In Open Source Cloud Computing
 
Great Wide Open: Crash Course Open Source Cloud Computing - 2014
Great Wide Open: Crash Course Open Source Cloud Computing - 2014Great Wide Open: Crash Course Open Source Cloud Computing - 2014
Great Wide Open: Crash Course Open Source Cloud Computing - 2014
 
Framework engineering JCO 2011
Framework engineering JCO 2011Framework engineering JCO 2011
Framework engineering JCO 2011
 
The software design principles
The software design principlesThe software design principles
The software design principles
 
C# .NET: Language Features and Creating .NET Projects, Namespaces Classes and...
C# .NET: Language Features and Creating .NET Projects, Namespaces Classes and...C# .NET: Language Features and Creating .NET Projects, Namespaces Classes and...
C# .NET: Language Features and Creating .NET Projects, Namespaces Classes and...
 

Clean Code - Design Patterns and Best Practices for Bay.NET SF User Group (01/16/2013)

  • 1. Bay.NET San Francisco Clean Code Design Patterns and Best Practices San Francisco, January 16th 2013
  • 2. Theo Jungeblut • Engineering manager & lead by day at AppDynamics in San Francisco • Coder & software craftsman by night • Architects decoupled solutions tailored to business needs & crafts maintainable code to last • Worked in healthcare and factory automation, building mission critical applications, framework & platforms • Degree in Software Engineering and Network Communications theo@designitright.net • Enjoys cycling, running and eating www.designitright.net
  • 3. Rate Session & Win a Shirt http://www.speakerrate.com/theoj
  • 4. Where to get the Slides http://www.slideshare.net/theojungeblut
  • 5. Overview • Why Clean Code • Clean Code Developer Initiative • Principles and Practices • Code Comparison • Q&A
  • 6. Does writing Clean Code make us more efficient?
  • 7. The only valid Measurement of Code Quality
  • 9. Clean Code is maintainable Source code must be: • readable & well structured • extensible • testable
  • 10. Software Engineering & Software Craftsmanship
  • 11. The “Must Read”-Book(s) by Robert C Martin A Handbook of Agile Software Craftsmanship “Even bad code can function. But if code isn’t clean, it can bring a development organization to its knees.”
  • 12. Code Maintainability * Principles Patterns Containers Why? How? What? Extensibility Clean Code Tool reuse * from: Mark Seemann’s “Dependency Injection in .NET” presentation Bay.NET 05/2011
  • 13. Clean Code Developer Graphic by Michael Hönnig http://michael.hoennig.de/2009/08/08/clean-code-developer-ccd/
  • 14. Clean Code Developer – 1st Iteration by Ralf Westphal & Stefan Lieser – http://www.clean-code-developer.de Graphic by Michael Hönnig http://michael.hoennig.de/2009/08/08/clean-code-developer-ccd/
  • 15. Keep it simple, stupid (KISS)
  • 16. KISS-Principle – “Keep It Simple Stupid” by Kelly Johnson http://blogs.smarter.com/blogs/Lego%20Brick.jpg
  • 17. The Power of Simplicity Graphic by Nathan Sawaya courtesy of brickartist.com Graphic by Nathan Sawaya courtesy of brickartist.com http://www.geekalerts.com/lego-iphone/
  • 18. Chaos build from simplicity Graphic by Nathan Sawaya courtesy of brickartist.com
  • 20. Don’t repeat yourself (DRY) by Andy Hunt and Dave Thomas in their book “The Pragmatic Programmer” // Code Copy and Paste Method // DRY Method public Class Person public Class Person { { public string FirstName { get; set;} public string FirstName { get; set;} public string LastName { get; set;} public string LastName { get; set;} public Person(Person person) public Person(Person person) { { this.FirstName = string.IsNullOrEmpty(person.FirstName) this.FirstName = person.FirstName.CloneSecured(); ? string.Empty : (string) person.FirstName.Clone(); this.LastName = person.LastName.CloneSecured(); } this.LastName = string.IsNullOrEmpty(person.LastName) ? string.Empty : (string) person.LastName.Clone(); public object Clone() } { return new Person(this); public object Clone() } { } return new Person(this); } } public static class StringExtension { public static string CloneSecured(this string original) { return string.IsNullOrEmpty(original) ? string.Empty : (string)original.Clone(); } }
  • 21. Clean Code Developer – 1st Iteration by Ralf Westphal & Stefan Lieser – http://www.clean-code-developer.de Graphic by Michael Hönnig http://michael.hoennig.de/2009/08/08/clean-code-developer-ccd/
  • 22. Clean Code Developer – 2nd Iteration by Ralf Westphal & Stefan Lieser – http://www.clean-code-developer.de Graphic by Michael Hönnig http://michael.hoennig.de/2009/08/08/clean-code-developer-ccd/
  • 23. Separation of Concerns (SoC) Single Responsibility Principle (SRP)
  • 25. Component / Service http://www.technicopedia.com/8865.html
  • 26. Class, Struct, Enum etc. http://technicbricks.blogspot.com/2009/06/tbs-techpoll-12-results-2009-1st.html
  • 27. Separation of Concerns (SoC) probably by Edsger W. Dijkstra in 1974 • “In computer science, separation of concerns (SoC) is the process of separating a computer program into distinct features that overlap in functionality as little as possible. •A concern is any piece of interest or focus in a program. Typically, concerns are synonymous with features or behaviors. “ http://en.wikipedia.org/wiki/Separati on_of_Concerns
  • 28. Single Responsibility Principle (SRP) by Robert C Martin “Every object should have a single responsibility, and that responsibility should be entirely encapsulated by the class.” http://en.wikipedia.org/wiki/Single_responsibility_principle public class Logger : ILogger { public Logger(ILoggingSink loggingSink) {} public void Log(string message) {} } http://www.ericalbrecht.com
  • 30. Clean Code Developer – 2nd Iteration by Ralf Westphal & Stefan Lieser – http://www.clean-code-developer.de Graphic by Michael Hönnig http://michael.hoennig.de/2009/08/08/clean-code-developer-ccd/
  • 31. Clean Code Developer – 3rd Iteration by Ralf Westphal & Stefan Lieser – http://www.clean-code-developer.de Graphic by Michael Hönnig http://michael.hoennig.de/2009/08/08/clean-code-developer-ccd/
  • 33. Information Hiding Principle (IHP) by David Parnas (1972) “.. information hiding is the principle of segregation of the design decisions on a computer program that are most likely to change, ..” http://en.wikipedia.org/wiki/Information_hiding
  • 34. Interfaces / Contracts • Decouple Usage and Implementation through introduction of a contract • Allows to replace implementation without changing the consumer public interface ILogger public class Logger : ILogger { { void Log(string message); public Logger(ILoggingSink loggingSink) } {} public void Log(string message) {} }
  • 36. Liskov Substitution Principle (LSP) by Barbara Liskov, Jannette Wing (1994) “Liskov’s notion of a behavioral subtype defines a notion of substitutability for mutable objects” http://en.wikipedia.org/wiki/Liskov_substitution_principle
  • 38. Dependency Inversion Principle (DIP) by Robert C. Martin • “High-level modules should not depend on low-level modules. Both should depend on abstractions. • Abstractions should not depend upon details. Details should depend upon abstractions.” http://en.wikipedia.org/wiki/Dependency_inversion_principle
  • 39. Silicon Valley Code Camp Oct. ~ 5th – 6th http://www.siliconvalley-codecamp.com
  • 40. Clean Code Developer – 3rd Iteration by Ralf Westphal & Stefan Lieser – http://www.clean-code-developer.de Graphic by Michael Hönnig http://michael.hoennig.de/2009/08/08/clean-code-developer-ccd/
  • 41. Clean Code Developer – 4th Iteration by Ralf Westphal & Stefan Lieser – http://www.clean-code-developer.de Graphic by Michael Hönnig http://michael.hoennig.de/2009/08/08/clean-code-developer-ccd/
  • 43. Open/Closed Principle (OCP) by Bertrand Meyer (1988) An implementation is open for extension but closed for modification http://en.wikipedia.org/wiki/Open/closed_principle
  • 44. Law of Demeter (LoD)
  • 45. Law of Demeter (LoD) Northeastern University (1987) “ • 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.” http://en.wikipedia.org/wiki/Law_Of_Demeter
  • 46. S Single Responsibility Principle O Open/Closed Principle L Liskov Substitution Principle I Interface Segregation Principle D Dependency Inversion Principle Robert C Martin: http://butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod
  • 47. Clean Code Developer – 4th Iteration by Ralf Westphal & Stefan Lieser – http://www.clean-code-developer.de Graphic by Michael Hönnig http://michael.hoennig.de/2009/08/08/clean-code-developer-ccd/
  • 48. Clean Code Developer – 5th Iteration by Ralf Westphal & Stefan Lieser – http://www.clean-code-developer.de Graphic by Michael Hönnig http://michael.hoennig.de/2009/08/08/clean-code-developer-ccd/
  • 49. Summary Clean Code Maintainability is achieved through: • Readability (Coding Guidelines) • Simplification and Specialization (KISS, SoC, SRP, OCP, ) • Decoupling (LSP, DIP, IHP, Contracts, LoD, CoP, IoC or SOA) • Avoiding Code Bloat (DRY, YAGNI) • Quality through Testability (all of them!)
  • 50. Q&A Downloads, Feedback & Comments: theo@designitright.net www.designitright.net www.speakerrate.com/theoj Graphic by Nathan Sawaya courtesy of brickartist.com
  • 51. http://clean-code-developer.com References… http://michael.hoennig.de/2009/08/08/clean-code-developer-ccd/ http://butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod http://www.manning.com/seemann/ http://en.wikipedia.org/wiki/Keep_it_simple_stupid http://picocontainer.org/patterns.html http://en.wikipedia.org/wiki/Separation_of_concerns http://en.wikipedia.org/wiki/Single_responsibility_principle http://en.wikipedia.org/wiki/Information_hiding http://en.wikipedia.org/wiki/Liskov_substitution_principle http://en.wikipedia.org/wiki/Dependency_inversion_principle http://en.wikipedia.org/wiki/Open/closed_principle http://en.wikipedia.org/wiki/Law_Of_Demeter http://en.wikipedia.org/wiki/Don't_repeat_yourself http://en.wikipedia.org/wiki/You_ain't_gonna_need_it http://en.wikipedia.org/wiki/Component-oriented_programming http://en.wikipedia.org/wiki/Service-oriented_architecture http://www.martinfowler.com/articles/injection.html http://www.codeproject.com/KB/aspnet/IOCDI.aspx http://msdn.microsoft.com/en-us/magazine/cc163739.aspx http://msdn.microsoft.com/en-us/library/ff650320.aspx http://msdn.microsoft.com/en-us/library/aa973811.aspx http://msdn.microsoft.com/en-us/library/ff647976.aspx http://msdn.microsoft.com/en-us/library/cc707845.aspx http://msdn.microsoft.com/en-us/library/bb833022.aspx http://unity.codeplex.com/ http://www.idesign.net/idesign/DesktopDefault.aspx?tabindex=5&tabid=11
  • 52. … more References Resharper http://www.jetbrains.com/resharper/ FxCop / Code Analysis http://msdn.microsoft.com/en-us/library/bb429476(VS.80).aspx http://blogs.msdn.com/b/codeanalysis/ http://www.binarycoder.net/fxcop/index.html Code Contracts http://msdn.microsoft.com/en-us/devlabs/dd491992 http://research.microsoft.com/en-us/projects/contracts/ Pex & Mole http://research.microsoft.com/en-us/projects/pex/ StyleCop http://stylecop.codeplex.com/ Ghostdoc http://submain.com/products/ghostdoc.aspx Spellchecker http://visualstudiogallery.msdn.microsoft.com/ 7c8341f1-ebac-40c8-92c2-476db8d523ce// Lego (trademarked in capitals as LEGO)
  • 54. Please fill out the feedback, and… … thanks for you attention!

Notes de l'éditeur

  1. A object or any type implementing subtype or a certain interface can be replaced with another object implementing the same base type or interface.