Successfully reported this slideshow.
Evergreen Valley College, Oct. 3rd, 2015
Clean Code I
Best Practices
Theo Jungeblut
• Director Customer Success at
AppDynamics in San Francisco
• Coder & software craftsman by night,
first ti...
We are hiring!
http://www.appdynamics.com/ careers
Your feedback is important!
http://speakerrate.com/speakers/18667-theo-jungeblut
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 Maintainability *
Principles Patterns Containers
Why? How? What?
Extensibility Clean Code Tool reuse
* from: Mark See...
Clean Code Developer
Graphic by Michael Hönnig http://michael.hoennig.de/2009/08/08/clean-code-developer-ccd/
The 4 values of the CCD initiative
• Correctness
• Evolvability
• Production Efficiency
• Continuous Improvement
http://bl...
Graphic by Michael Hönnig http://michael.hoennig.de/2009/08/08/clean-code-developer-ccd/
Clean Code Developer – 1st Iterat...
Keep it simple, stupid
(KISS)
KISS-Principle – “Keep It Simple Stupid”
http://blogs.smarter.com/blogs/Lego%20Brick.jpg
by Kelly Johnson
The Power of Simplicity
http://www.geekalerts.com/lego-iphone/
Graphic by Nathan Sawaya courtesy of brickartist.com
Graphi...
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 M...
Graphic by Michael Hönnig http://michael.hoennig.de/2009/08/08/clean-code-developer-ccd/
Clean Code Developer – 1st Iterat...
Clean Code Developer – 2nd Iteration
by Ralf Westphal & Stefan Lieser – http://www.clean-code-developer.de
Graphic by Mich...
Separation of Concerns
(SoC)
Single Responsibility
Principle
(SRP)
http://www.technicopedia.com/8865.html
The Product
http://www.technicopedia.com/8865.html
Component / Service
http://technicbricks.blogspot.com/2009/06/tbs-techpoll-12-results-2009-1st.html
Class, Struct, Enum etc.
Separation of Concerns (SoC)
• “In computer science, separation
of concerns (SoC) is the process of
separating a computer ...
Single Responsibility Principle (SRP)
“Every object should have a single responsibility, and that
responsibility should be...
Read, Read, Read
Clean Code Developer – 2nd Iteration
by Ralf Westphal & Stefan Lieser – http://www.clean-code-developer.de
Graphic by Mich...
Graphic by Michael Hönnig http://michael.hoennig.de/2009/08/08/clean-code-developer-ccd/
Clean Code Developer – 3rd Iterat...
Information Hiding
Principle
(IHP)
“.. information hiding is the principle of
segregation of the design decisions on a
computer program that are most likely ...
Interfaces / Contracts
public interface ILogger
{
void Log(string message);
}
• Decouple Usage and Implementation through ...
Liskov Substitution
Principle
(LSP)
“Liskov’s notion of a behavioral subtype
defines a notion of substitutability for
mutable objects”
Liskov Substitution Pri...
Dependency Inversion
Principle
(DIP)
Dependency Inversion Principle (DIP)
• “High-level modules should not depend on low-level
modules. Both should depend on a...
Next Silicon Valley Code Camp Oct. 2016
https://www.siliconvalley-codecamp.com
Mini Conferences – User Groups 
Graphic by Michael Hönnig http://michael.hoennig.de/2009/08/08/clean-code-developer-ccd/
Clean Code Developer – 3rd Iterat...
Graphic by Michael Hönnig http://michael.hoennig.de/2009/08/08/clean-code-developer-ccd/
Clean Code Developer – 4th Iterat...
Open Closed Principle
(OCP)
An implementation is open for extension
but closed for modification
Open/Closed Principle (OCP)
by Bertrand Meyer (1988)
h...
Law of Demeter
(LoD)
“
• Each unit should have only limited knowledge about
other units: only units “closely” related to the
current unit.
• Ea...
Single Responsibility Principle
Open/Closed Principle
Liskov Substitution Principle
Interface Segregation Principle
Depend...
Graphic by Michael Hönnig http://michael.hoennig.de/2009/08/08/clean-code-developer-ccd/
Clean Code Developer – 4th Iterat...
Graphic by Michael Hönnig http://michael.hoennig.de/2009/08/08/clean-code-developer-ccd/
Clean Code Developer – 5th Iterat...
Clean Code Developer
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 Specializat...
Downloads,
Feedback & Comments:
Q & A
Graphic by Nathan Sawaya courtesy of brickartist.com
theo@designitright.net
www.desi...
Time to say Thank You!
The Organizers
Evergreen Valley College (team)
The volunteers (how about you?)
TheSponsors
Pictures...
References…http://clean-code-developer.com
http://blogs.telerik.com/justteam/posts/13-05-16/clean-code-developer-school
ht...
… more References
Resharper
http://www.jetbrains.com/resharper/
FxCop / Code Analysis
http://msdn.microsoft.com/en-us/libr...
Blog, Rating, Slides
http://www.DesignItRight.net
http://speakerrate.com/speake
rs/18667-theo-jungeblut
www.slideshare.net...
… thanks for you attention!
And visit and support the
www.siliconvalley-codecamp.com
Please fill out the
feedback, and…
ww...
Prochain SlideShare
Chargement dans…5
×

Clean Code I - Best Practices

9 407 vues

Publié le

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 and 3rd 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 2012. However, the demonstrated patterns and practice can be applied to every other programming language too.

Note: Moving forwards this presentation will be updated with the latest version of the slides for the last event I did the presentation instead of creating new separate slide decks here on SlideShare.

Presentation dates and locations:
2015-10-03 Silicon Valley Code Camp, San Jose, CA
2015-06-27 SoCal Code Camp - San Diego, CA
2014-11-14 SoCal Code Camp - Los Angeles, CA
2014-10-18 Desert Code Camp - Chandler, AZ
2014-10-11 Silicon Valley Code Camp, Los Altos Hills, CA

Publié dans : Technologie
  • Soyez le premier à commenter

Clean Code I - Best Practices

  1. 1. Evergreen Valley College, Oct. 3rd, 2015 Clean Code I Best Practices
  2. 2. Theo Jungeblut • Director Customer Success at AppDynamics in San Francisco • Coder & software craftsman by night, first time dad and house builder • Architects decoupled solutions & crafts maintainable code to last • Worked in healthcare and factory automation, building mission critical applications, framework & platforms • Degree in Software Engineering and Network Communications • Enjoys cycling, running and eating theo@designitright.net www.designitright.net
  3. 3. We are hiring! http://www.appdynamics.com/ careers
  4. 4. Your feedback is important! http://speakerrate.com/speakers/18667-theo-jungeblut
  5. 5. Where to get the Slides http://www.slideshare.net/theojungeblut
  6. 6. Overview • Why Clean Code • Clean Code Developer Initiative • Principles and Practices • Code Comparison • Q&A
  7. 7. Does writing Clean Code make us more efficient?
  8. 8. The only valid Measurement of Code Quality
  9. 9. What is Clean Code?
  10. 10. Clean Code is maintainable Source code must be: • readable & well structured • extensible • testable
  11. 11. Software Engineering & Software Craftsmanship
  12. 12. 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.”
  13. 13. 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
  14. 14. Clean Code Developer Graphic by Michael Hönnig http://michael.hoennig.de/2009/08/08/clean-code-developer-ccd/
  15. 15. The 4 values of the CCD initiative • Correctness • Evolvability • Production Efficiency • Continuous Improvement http://blogs.telerik.com/justteam/posts/13-05-16/clean-code-developer-school by Ralf Westphal & Stefan Lieser – http://www.clean-code-developer.de
  16. 16. 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
  17. 17. Keep it simple, stupid (KISS)
  18. 18. KISS-Principle – “Keep It Simple Stupid” http://blogs.smarter.com/blogs/Lego%20Brick.jpg by Kelly Johnson
  19. 19. The Power of Simplicity http://www.geekalerts.com/lego-iphone/ Graphic by Nathan Sawaya courtesy of brickartist.com Graphic by Nathan Sawaya courtesy of brickartist.com
  20. 20. Chaos build from simplicity Graphic by Nathan Sawaya courtesy of brickartist.com
  21. 21. Don’t repeat yourself (DRY)
  22. 22. Don’t repeat yourself (DRY) by Andy Hunt and Dave Thomas in their book “The Pragmatic Programmer” // Code Copy and Paste Method public Class Person { public string FirstName { get; set;} public string LastName { get; set;} public Person(Person person) { this.FirstName = string.IsNullOrEmpty(person.FirstName) ? string.Empty : string.Copy(person.FirstName); this.LastName = string.IsNullOrEmpty(person.LastName) ? string.Empty : string.Copy(person.LastName); } public object Clone() { return new Person(this); } } // DRY Method public Class Person { public string FirstName { get; set;} public string LastName { get; set;} public Person(Person person) { this.FirstName = person.FirstName.CloneSecured(); this.LastName = person.LastName.CloneSecured(); } 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.Copy(original); } }
  23. 23. 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
  24. 24. 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/
  25. 25. Separation of Concerns (SoC) Single Responsibility Principle (SRP)
  26. 26. http://www.technicopedia.com/8865.html The Product
  27. 27. http://www.technicopedia.com/8865.html Component / Service
  28. 28. http://technicbricks.blogspot.com/2009/06/tbs-techpoll-12-results-2009-1st.html Class, Struct, Enum etc.
  29. 29. Separation of Concerns (SoC) • “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. “ probably by Edsger W. Dijkstra in 1974 http://en.wikipedia.org/wiki/Separation_of_Concerns
  30. 30. Single Responsibility Principle (SRP) “Every object should have a single responsibility, and that responsibility should be entirely encapsulated by the class.” by Robert C Martin http://www.ericalbrecht.com http://en.wikipedia.org/wiki/Single_responsibility_principle public class Logger : ILogger { public Logger(ILoggingSink loggingSink) {} public void Log(string message) {} }
  31. 31. Read, Read, Read
  32. 32. 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/
  33. 33. 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
  34. 34. Information Hiding Principle (IHP)
  35. 35. “.. information hiding is the principle of segregation of the design decisions on a computer program that are most likely to change, ..” Information Hiding Principle (IHP) by David Parnas (1972) http://en.wikipedia.org/wiki/Information_hiding
  36. 36. Interfaces / Contracts public interface ILogger { void Log(string message); } • Decouple Usage and Implementation through introduction of a contract • Allows to replace implementation without changing the consumer public class Logger : ILogger { public Logger(ILoggingSink loggingSink) {} public void Log(string message) {} }
  37. 37. Liskov Substitution Principle (LSP)
  38. 38. “Liskov’s notion of a behavioral subtype defines a notion of substitutability for mutable objects” Liskov Substitution Principle (LSP) by Barbara Liskov, Jannette Wing (1994) http://en.wikipedia.org/wiki/Liskov_substitution_principle http://www.objectmentor.com/resources/articles/lsp.pdf
  39. 39. Dependency Inversion Principle (DIP)
  40. 40. Dependency Inversion Principle (DIP) • “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 http://www.objectmentor.com/resources/articles/dip.pdf by Robert C. Martin
  41. 41. Next Silicon Valley Code Camp Oct. 2016 https://www.siliconvalley-codecamp.com
  42. 42. Mini Conferences – User Groups 
  43. 43. 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
  44. 44. 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
  45. 45. Open Closed Principle (OCP)
  46. 46. An implementation is open for extension but closed for modification Open/Closed Principle (OCP) by Bertrand Meyer (1988) http://en.wikipedia.org/wiki/Open/closed_principle
  47. 47. Law of Demeter (LoD)
  48. 48. “ • 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.” Law of Demeter (LoD) Northeastern University (1987) http://en.wikipedia.org/wiki/Law_Of_Demeter
  49. 49. Single Responsibility Principle Open/Closed Principle Liskov Substitution Principle Interface Segregation Principle Dependency Inversion Principle S O L I D Robert C Martin: http://butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod
  50. 50. 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
  51. 51. 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
  52. 52. Clean Code Developer Graphic by Michael Hönnig http://michael.hoennig.de/2009/08/08/clean-code-developer-ccd/
  53. 53. 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!)
  54. 54. Downloads, Feedback & Comments: Q & A Graphic by Nathan Sawaya courtesy of brickartist.com theo@designitright.net www.designitright.net http://speakerrate.com/ speakers /18667-theo-jungeblut
  55. 55. Time to say Thank You! The Organizers Evergreen Valley College (team) The volunteers (how about you?) TheSponsors Picturesfromhttp://blog.siliconvalley-codecamp.com
  56. 56. References…http://clean-code-developer.com http://blogs.telerik.com/justteam/posts/13-05-16/clean-code-developer-school 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://stackoverflow.com/questions/6766056/dip-vs-di-vs-ioc 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://unity.codeplex.com/ http://www.idesign.net/idesign/DesktopDefault.aspx?tabindex=5&tabid=11
  57. 57. … 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/ 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)
  58. 58. Blog, Rating, Slides http://www.DesignItRight.net http://speakerrate.com/speake rs/18667-theo-jungeblut www.slideshare.net/theojungeblut
  59. 59. … thanks for you attention! And visit and support the www.siliconvalley-codecamp.com Please fill out the feedback, and… www.speakerrate.com/theoj

×