SolCal                 CodeCampClean Code I  Design Patterns and Best Practices    San Diego, June 24rd 2012
Theo Jungeblut• Senior Software Developer at  AppDynamics in San Francisco• architects decoupled solutions  tailored to bu...
Overview•   Why Clean Code•   Clean Code Developer Initiative•   Principles and Practices•   Code Comparison•   Q&A
Does writing Clean Codemake 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      vs.Craftsmanship
Software Engineering     ANDCraftsmanship
The “Must Read”-Book(s) by Robert C MartinA Handbook of AgileSoftwareCraftsmanship“Even bad code canfunction. But if codei...
Code Maintainability *    Principles                   Patterns                   Containers       Why?                   ...
Clean Code DeveloperGraphic 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.deGraphic by M...
Keep it simple, stupid        (KISS)
KISS-Principle – “Keep It Simple Stupid”   by Kelly Johnson                      http://blogs.smarter.com/blogs/Lego%20Bri...
The Power of Simplicity                                                       Graphic by Nathan Sawaya courtesy of brickar...
Chaos build from simplicityGraphic 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 P...
Clean Code Developer – 1st Iteration     by Ralf Westphal & Stefan Lieser – http://www.clean-code-developer.deGraphic by M...
Clean Code Developer – 2nd Iteration     by Ralf Westphal & Stefan Lieser – http://www.clean-code-developer.deGraphic by M...
Separation of Concerns         (SoC) Single Responsibility       Principle         (SRP)
The Producthttp://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)...
Single Responsibility Principle (SRP)      by Robert C Martin“Every object should have a single responsibility, and thatre...
Read, Read, Read
Clean Code Developer – 2nd Iteration     by Ralf Westphal & Stefan Lieser – http://www.clean-code-developer.deGraphic by M...
SolCal                 CodeCampClean Code III      Software   Craftsmanship    San Diego, June 23rd 2012
Clean Code Developer – 3rd Iteration     by Ralf Westphal & Stefan Lieser – http://www.clean-code-developer.deGraphic by M...
Information Hiding Principle           (IHP)
Information Hiding Principle (IHP)         by David Parnas (1972)“.. information hiding is the principle ofsegregation of ...
Interfaces / Contracts• Decouple Usage and Implementation through introduction of a contract• Allows to replace implementa...
Liskov Substitution Principle           (LSP)
Liskov Substitution Principle (LSP)by Barbara Liskov, Jannette Wing (1994)“Liskov’s notion of a behavioral subtypedefines ...
Dependency Inversion Principle           (DIP)
Dependency Inversion Principle (DIP)  by Robert C. Martin• “High-level modules should not depend on  low-level modules. Bo...
Clean Code Developer – 3rd Iteration     by Ralf Westphal & Stefan Lieser – http://www.clean-code-developer.deGraphic by M...
Clean Code Developer – 4th Iteration     by Ralf Westphal & Stefan Lieser – http://www.clean-code-developer.deGraphic by M...
Open Closed Principle       (OCP)
Open/Closed Principle (OCP)by Bertrand Meyer (1988)An implementation is open for extensionbut closed for modification     ...
Law of Demeter     (LoD)
Law of Demeter (LoD)           Northeastern University (1987)“• Each unit should have only limited knowledge  about other ...
S               Single Responsibility Principle   O               Open/Closed Principle   L               Liskov Substitut...
Clean Code Developer – 4th Iteration     by Ralf Westphal & Stefan Lieser – http://www.clean-code-developer.deGraphic by M...
Silicon Valley Code Camp Oct. 6th – 7thhttp://www.siliconvalley-codecamp.com
Clean Code Developer – 5th Iteration     by Ralf Westphal & Stefan Lieser – http://www.clean-code-developer.deGraphic by M...
Summary Clean CodeMaintainability is achieved through:• Readability (Coding Guidelines)• Simplification and Specialization...
Q&A                                         Downloads,                                         Feedback & Comments:       ...
http://clean-code-developer.com                                          References…http://michael.hoennig.de/2009/08/08/c...
… more ReferencesResharperhttp://www.jetbrains.com/resharper/FxCop / Code Analysishttp://msdn.microsoft.com/en-us/library/...
Please fill out thefeedback, and…                          www.speakerrate.com/theoj… thanks for you attention!           ...
Upcoming SlideShare
Loading in...5
×

Clean Code Part I - Design Patterns at SoCal Code Camp

1,184

Published on

Within this session you will learn and/or refresh the most important architectural design pattern and best practices to write better code. These patterns and practices build the foundation for writing maintainable application. More advances techniques like Inversion of Control and Dependency Injection are discussed in detail in the 2nd Clean Code presentation.
All 3 Clean Code presentations provide great value by themselves, but taken together are designed to offer a holistic approach to successful software creation. This first session creates the foundation for the 2nd Clean Code presentation on Dependency Injection, as it explains expected base knowledge.

Why writing Clean Code makes us more efficient
Over the lifetime of a product, maintaining the product is actually one - if not the most - expensive area(s) of the overall product costs. Writing clean code can significantly lower these costs. However, writing clean code also makes you more efficient during the initial development time and results in more stable code. You will be presented design patterns and best practices which will make you write better and more easily maintainable code, seeing code in a holistic way. You will learn how to apply them by using an existing implementation as the starting point of the presentation. Finally, patterns & practices benefits are explained.
This presentation is based on C# and Visual Studio 2010. However, the demonstrated patterns and practice can be applied to every other programming language too.

Published in: Technology
0 Comments
5 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,184
On Slideshare
0
From Embeds
0
Number of Embeds
7
Actions
Shares
0
Downloads
50
Comments
0
Likes
5
Embeds 0
No embeds

No notes for slide
  • A object or any type implementing subtype or a certain interface can be replaced with another object implementing the same base type or interface.
  • Clean Code Part I - Design Patterns at SoCal Code Camp

    1. 1. SolCal CodeCampClean Code I Design Patterns and Best Practices San Diego, June 24rd 2012
    2. 2. Theo Jungeblut• Senior Software Developer at AppDynamics in San Francisco• architects decoupled solutions tailored to business needs and crafts maintainable code to last• worked in healthcare and factory automation, building mission critical applications, framework & platforms for 8+ years• degree in Software Engineering and Network Communications theo@designitright.net• enjoys cycling, running and eating www.designitright.net www.speakerrate.com/theoj
    3. 3. Overview• Why Clean Code• Clean Code Developer Initiative• Principles and Practices• Code Comparison• Q&A
    4. 4. Does writing Clean Codemake us more efficient?
    5. 5. The only valid Measurement of Code Quality
    6. 6. What is Clean Code?
    7. 7. Clean Code is maintainable Source code must be: • readable & well structured • extensible • testable
    8. 8. Software Engineering vs.Craftsmanship
    9. 9. Software Engineering ANDCraftsmanship
    10. 10. The “Must Read”-Book(s) by Robert C MartinA Handbook of AgileSoftwareCraftsmanship“Even bad code canfunction. But if codeisn’t clean, it can bring adevelopmentorganization to itsknees.”
    11. 11. 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
    12. 12. Clean Code DeveloperGraphic by Michael Hönnig http://michael.hoennig.de/2009/08/08/clean-code-developer-ccd/
    13. 13. Clean Code Developer – 1st Iteration by Ralf Westphal & Stefan Lieser – http://www.clean-code-developer.deGraphic by Michael Hönnig http://michael.hoennig.de/2009/08/08/clean-code-developer-ccd/
    14. 14. Keep it simple, stupid (KISS)
    15. 15. KISS-Principle – “Keep It Simple Stupid” by Kelly Johnson http://blogs.smarter.com/blogs/Lego%20Brick.jpg
    16. 16. The Power of Simplicity Graphic by Nathan Sawaya courtesy of brickartist.comGraphic by Nathan Sawaya courtesy of brickartist.com http://www.geekalerts.com/lego-iphone/
    17. 17. Chaos build from simplicityGraphic by Nathan Sawaya courtesy of brickartist.com
    18. 18. Don’t repeat yourself (DRY)
    19. 19. Don’t repeat yourself (DRY) by Andy Hunt and Dave Thomas in their book “The Pragmatic Programmer”// Code Copy and Paste Method // DRY Methodpublic 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(); } }
    20. 20. Clean Code Developer – 1st Iteration by Ralf Westphal & Stefan Lieser – http://www.clean-code-developer.deGraphic by Michael Hönnig http://michael.hoennig.de/2009/08/08/clean-code-developer-ccd/
    21. 21. Clean Code Developer – 2nd Iteration by Ralf Westphal & Stefan Lieser – http://www.clean-code-developer.deGraphic by Michael Hönnig http://michael.hoennig.de/2009/08/08/clean-code-developer-ccd/
    22. 22. Separation of Concerns (SoC) Single Responsibility Principle (SRP)
    23. 23. The Producthttp://www.technicopedia.com/8865.html
    24. 24. Component / Service http://www.technicopedia.com/8865.html
    25. 25. Class, Struct, Enum etc.http://technicbricks.blogspot.com/2009/06/tbs-techpoll-12-results-2009-1st.html
    26. 26. Separation of Concerns (SoC) probably by Edsger W. Dijkstra in 1974• “In computer science,separation of concerns (SoC) isthe process of separating acomputer program into distinctfeatures that overlap infunctionality as little as possible.•A concern is any piece ofinterest or focus in a program.Typically, concerns aresynonymous with features orbehaviors. “ http://en.wikipedia.org/wiki/Separati on_of_Concerns
    27. 27. Single Responsibility Principle (SRP) by Robert C Martin“Every object should have a single responsibility, and thatresponsibility should be entirely encapsulated by the class.” http://en.wikipedia.org/wiki/Single_responsibility_principlepublic class Logger : ILogger{ public Logger(ILoggingSink loggingSink) {} public void Log(string message) {}} http://www.ericalbrecht.com
    28. 28. Read, Read, Read
    29. 29. Clean Code Developer – 2nd Iteration by Ralf Westphal & Stefan Lieser – http://www.clean-code-developer.deGraphic by Michael Hönnig http://michael.hoennig.de/2009/08/08/clean-code-developer-ccd/
    30. 30. SolCal CodeCampClean Code III Software Craftsmanship San Diego, June 23rd 2012
    31. 31. Clean Code Developer – 3rd Iteration by Ralf Westphal & Stefan Lieser – http://www.clean-code-developer.deGraphic by Michael Hönnig http://michael.hoennig.de/2009/08/08/clean-code-developer-ccd/
    32. 32. Information Hiding Principle (IHP)
    33. 33. Information Hiding Principle (IHP) by David Parnas (1972)“.. information hiding is the principle ofsegregation of the design decisions on acomputer program that are most likely tochange, ..” http://en.wikipedia.org/wiki/Information_hiding
    34. 34. Interfaces / Contracts• Decouple Usage and Implementation through introduction of a contract• Allows to replace implementation without changing the consumerpublic interface ILogger public class Logger : ILogger{ { void Log(string message); public Logger(ILoggingSink loggingSink)} {} public void Log(string message) {} }
    35. 35. Liskov Substitution Principle (LSP)
    36. 36. Liskov Substitution Principle (LSP)by Barbara Liskov, Jannette Wing (1994)“Liskov’s notion of a behavioral subtypedefines a notion of substitutability formutable objects” http://en.wikipedia.org/wiki/Liskov_substitution_principle
    37. 37. Dependency Inversion Principle (DIP)
    38. 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. 39. Clean Code Developer – 3rd Iteration by Ralf Westphal & Stefan Lieser – http://www.clean-code-developer.deGraphic by Michael Hönnig http://michael.hoennig.de/2009/08/08/clean-code-developer-ccd/
    40. 40. Clean Code Developer – 4th Iteration by Ralf Westphal & Stefan Lieser – http://www.clean-code-developer.deGraphic by Michael Hönnig http://michael.hoennig.de/2009/08/08/clean-code-developer-ccd/
    41. 41. Open Closed Principle (OCP)
    42. 42. Open/Closed Principle (OCP)by Bertrand Meyer (1988)An implementation is open for extensionbut closed for modification http://en.wikipedia.org/wiki/Open/closed_principle
    43. 43. Law of Demeter (LoD)
    44. 44. 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
    45. 45. S Single Responsibility Principle O Open/Closed Principle L Liskov Substitution Principle I Interface Segregation Principle D Dependency Inversion PrincipleRobert C Martin: http://butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod
    46. 46. Clean Code Developer – 4th Iteration by Ralf Westphal & Stefan Lieser – http://www.clean-code-developer.deGraphic by Michael Hönnig http://michael.hoennig.de/2009/08/08/clean-code-developer-ccd/
    47. 47. Silicon Valley Code Camp Oct. 6th – 7thhttp://www.siliconvalley-codecamp.com
    48. 48. Clean Code Developer – 5th Iteration by Ralf Westphal & Stefan Lieser – http://www.clean-code-developer.deGraphic by Michael Hönnig http://michael.hoennig.de/2009/08/08/clean-code-developer-ccd/
    49. 49. Summary Clean CodeMaintainability 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. 50. Q&A Downloads, Feedback & Comments: theo@designitright.net www.designitright.net www.speakerrate.com/theojGraphic by Nathan Sawaya courtesy of brickartist.com
    51. 51. http://clean-code-developer.com References…http://michael.hoennig.de/2009/08/08/clean-code-developer-ccd/http://butunclebob.com/ArticleS.UncleBob.PrinciplesOfOodhttp://www.manning.com/seemann/http://en.wikipedia.org/wiki/Keep_it_simple_stupidhttp://picocontainer.org/patterns.htmlhttp://en.wikipedia.org/wiki/Separation_of_concernshttp://en.wikipedia.org/wiki/Single_responsibility_principlehttp://en.wikipedia.org/wiki/Information_hidinghttp://en.wikipedia.org/wiki/Liskov_substitution_principlehttp://en.wikipedia.org/wiki/Dependency_inversion_principlehttp://en.wikipedia.org/wiki/Open/closed_principlehttp://en.wikipedia.org/wiki/Law_Of_Demeterhttp://en.wikipedia.org/wiki/Dont_repeat_yourselfhttp://en.wikipedia.org/wiki/You_aint_gonna_need_ithttp://en.wikipedia.org/wiki/Component-oriented_programminghttp://en.wikipedia.org/wiki/Service-oriented_architecturehttp://www.martinfowler.com/articles/injection.htmlhttp://www.codeproject.com/KB/aspnet/IOCDI.aspxhttp://msdn.microsoft.com/en-us/magazine/cc163739.aspxhttp://msdn.microsoft.com/en-us/library/ff650320.aspxhttp://msdn.microsoft.com/en-us/library/aa973811.aspxhttp://msdn.microsoft.com/en-us/library/ff647976.aspxhttp://msdn.microsoft.com/en-us/library/cc707845.aspxhttp://msdn.microsoft.com/en-us/library/bb833022.aspxhttp://unity.codeplex.com/http://www.idesign.net/idesign/DesktopDefault.aspx?tabindex=5&tabid=11
    52. 52. … more ReferencesResharperhttp://www.jetbrains.com/resharper/FxCop / Code Analysishttp://msdn.microsoft.com/en-us/library/bb429476(VS.80).aspxhttp://blogs.msdn.com/b/codeanalysis/http://www.binarycoder.net/fxcop/index.htmlCode Contractshttp://msdn.microsoft.com/en-us/devlabs/dd491992http://research.microsoft.com/en-us/projects/contracts/Pex & Molehttp://research.microsoft.com/en-us/projects/pex/StyleCophttp://stylecop.codeplex.com/Ghostdochttp://submain.com/products/ghostdoc.aspxSpellcheckerhttp://visualstudiogallery.msdn.microsoft.com/7c8341f1-ebac-40c8-92c2-476db8d523ce// Lego (trademarked in capitals as LEGO)
    53. 53. Please fill out thefeedback, and… www.speakerrate.com/theoj… thanks for you attention! And visit and support the www.sandiegodotnet.com
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×