Clean Code III
Software
Craftsmanship
San Diego, July 27th, 2013
SolCal
Code Camp
Theo Jungeblut
• Engineering manager & lead by day
at AppDynamics in San Francisco
• Coder & software craftsman by night
•...
Overview
• Why Clean Code?
• The Power of Simplicity
• Tools - Your Best Friend
• From Names to Classes
• The "Must Read"-...
Does writing Clean Code
make us more efficient?
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 c...
Code Maintainability *
Principles Patterns Containers
Why? How? What?
Extensibility Clean Code Tool reuse
* from: Mark See...
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...
Graphic by Nathan Sawaya courtesy of brickartist.com
Source Code Conventions
.NET Tools and their Impact
Tool name Positive Impact Negative Impact
Resharper compiling ++++,
learning +++
VS responsive...
Resharper
Features:
– Code Analysis
– Quick Fixes
– Code Templates
– Code Generation
– Code Cleanup
– Many, many more…
“Th...
FxCop / Static Code Analysis
Code Analysis:
– Correctness
– Library design
– Internationalization and localization
– Namin...
Style Cop with R# Integration
Code Consistency & Readability:
– Automated check of C# coding
standard
– Enforceable at che...
http://submain.com/products/ghostdoc.aspx
• Save keystrokes and time
• Simplify documenting your code
• Benefit of the bas...
Spell Checker
http://visualstudiogallery.msdn.microsoft.com/7c8341f1-ebac-40c8-92c2-476db8d523ce/
• Spelll chicking for li...
http://msdn.microsoft.com/en-us/devlabs/dd491992
• Design-by-Contract programming
• Improved testability
• Static verifica...
• Pex automatically generates test suites with
high code coverage.
• Moles allows to replace any .NET method with
a delega...
Names Matter
• Meaningful Names
• Intention Revealing Names
• Use Pronounceable Names
• Use Searchable Names
• Avoid Encod...
Functions
• Small – Do One Thing
• One Level of Abstraction
• No or only few Arguments
• Have No Side Effects
• Prefer Exc...
Comments
• Comments do not Make Up for Bad Code
• Explain Yourself in Code
• Clarification
• Warning of Consequences
• ToD...
Bad Comments
• Mumblings
• Redundant Comments
• Misleading Comments
• Journal Comments
• Noise Comments
• Don’t use a Comm...
The Purpose of Formatting
• Team Rules – Consistency is King
• Vertical Openness Between Concepts
• Vertical Distance
• Ho...
Classes
• Class Organization
• Encapsulation
• Classes Should be Small
• The Single Responsibility Principle
• Cohesion
• ...
The “Must Read”-Book(s)by Robert C Martin
A Handbook of Agile
Software
Craftsmanship
“Even bad code can
function. But if c...
The “Must Read”-Book(s)by Krzysztof Cwalina, Brad Abrams
Framework Design
Guidelines
“teaches
developers the
best practice...
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...
References…http://clean-code-developer.com
http://michael.hoennig.de/2009/08/08/clean-code-developer-ccd/
http://butuncleb...
… 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
www.speakerrate.com/theoj
www.slideshare.net/theojungeblut
… thanks for you attention!
And visit and support the
www.sandiegodotnet.com
Please fill out the
feedback, and…
www.speake...
Clean Code III - Software Craftsmanship at SoCal Code Camp San Diego (07/27/2013)
Upcoming SlideShare
Loading in...5
×

Clean Code III - Software Craftsmanship at SoCal Code Camp San Diego (07/27/2013)

2,510

Published on

You will learn why naming is really difficult if done right, why coding and style guidelines are crucial, code structuring, exception handling and why other elements of coding often define the tipping point between success and failure of projects. Following the principles of software craftsmanship will allow you to end up with better maintainability and extensibility of your software and the success of the project in the end. All 3 Clean Code presentations provide great value by themselves, but taken together are designed to offer a holistic approach to successful software creation.

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.

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,510
On Slideshare
0
From Embeds
0
Number of Embeds
6
Actions
Shares
0
Downloads
43
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Clean Code III - Software Craftsmanship at SoCal Code Camp San Diego (07/27/2013)

  1. 1. Clean Code III Software Craftsmanship San Diego, July 27th, 2013 SolCal Code Camp
  2. 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 • Enjoys cycling, running and eating theo@designitright.net www.designitright.net
  3. 3. Overview • Why Clean Code? • The Power of Simplicity • Tools - Your Best Friend • From Names to Classes • The "Must Read"-Books • Summary • Q&A
  4. 4. Does writing Clean Code make us more efficient?
  5. 5. What is Clean Code?
  6. 6. Clean Code is maintainable Source code must be: • readable & well structured • extensible • testable
  7. 7. Software Engineering & Software Craftsmanship
  8. 8. 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.”
  9. 9. 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
  10. 10. Keep it simple, stupid (KISS)
  11. 11. KISS-Principle – “Keep It Simple Stupid” http://blogs.smarter.com/blogs/Lego%20Brick.jpg by Kelly Johnson
  12. 12. 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
  13. 13. Graphic by Nathan Sawaya courtesy of brickartist.com
  14. 14. Source Code Conventions
  15. 15. .NET Tools and their Impact Tool name Positive Impact Negative Impact Resharper compiling ++++, learning +++ VS responsiveness -- FxCop code quality ++ compiling time - StyleCop code consistency +++ compiling time - StyleCop plugin for Resharper compiling time +++ VS responsiveness -- Ghost Doc automated docs potentially worse doc Spell Checker fewer spelling errors ++ performance -- Code Contracts testability, quality ++ compiling time -- Pex & Moles automated test ++ compiling time --
  16. 16. Resharper Features: – Code Analysis – Quick Fixes – Code Templates – Code Generation – Code Cleanup – Many, many more… “The single most impacting development addition to Visual Studio” http://www.jetbrains.com/resharper/
  17. 17. FxCop / Static Code Analysis Code Analysis: – Correctness – Library design – Internationalization and localization – Naming conventions – Performance – Security http://msdn.microsoft.com/en-us/library/3z0aeatx.aspx
  18. 18. Style Cop with R# Integration Code Consistency & Readability: – Automated check of C# coding standard – Enforceable at check-in with TFS check-in Policy – Full Integration in Resharper with Style Cop plugin: – Code Analysis – Quick Fixes – Code Cleanup
  19. 19. http://submain.com/products/ghostdoc.aspx • Save keystrokes and time • Simplify documenting your code • Benefit of the base class documentation Ghost Doc
  20. 20. Spell Checker http://visualstudiogallery.msdn.microsoft.com/7c8341f1-ebac-40c8-92c2-476db8d523ce/ • Spelll chicking for literals and comments in VS
  21. 21. http://msdn.microsoft.com/en-us/devlabs/dd491992 • Design-by-Contract programming • Improved testability • Static verification • API documentation integration with Sandcastle
  22. 22. • Pex automatically generates test suites with high code coverage. • Moles allows to replace any .NET method with a delegate. Microsoft Pex & Moles http://research.microsoft.com/en-us/projects/pex/
  23. 23. Names Matter • Meaningful Names • Intention Revealing Names • Use Pronounceable Names • Use Searchable Names • Avoid Encoding (Hungarian) • Don’t be cute • Pick One Word per Concept • Use Problem Domain Names * Chapter extract: Robert C. Martin –” Clean Code”, Parson Education, Inc. 2008
  24. 24. Functions • Small – Do One Thing • One Level of Abstraction • No or only few Arguments • Have No Side Effects • Prefer Exceptions to Returning Error Codes • Don’t Repeat Yourself * Chapter extract: Robert C. Martin –” Clean Code”, Parson Education, Inc. 2008
  25. 25. Comments • Comments do not Make Up for Bad Code • Explain Yourself in Code • Clarification • Warning of Consequences • ToDo Comments • Javadocs in Public APIs * Chapter extract: Robert C. Martin –” Clean Code”, Parson Education, Inc. 2008
  26. 26. Bad Comments • Mumblings • Redundant Comments • Misleading Comments • Journal Comments • Noise Comments • Don’t use a Comment When you Use a Method or a Variable • Commented-Out Code * Chapter extract: Robert C. Martin –” Clean Code”, Parson Education, Inc. 2008
  27. 27. The Purpose of Formatting • Team Rules – Consistency is King • Vertical Openness Between Concepts • Vertical Distance • Horizontal Alignment • Indentation • Write Journey Style Code  Resharper & StyleCop – “Code Cleanup” * Kind of Chapter extract: Robert C. Martin –” Clean Code”, Parson Education, Inc. 2008
  28. 28. Classes • Class Organization • Encapsulation • Classes Should be Small • The Single Responsibility Principle • Cohesion • Organize for Change • Insolating from Change * Kind of Chapter extract: Robert C. Martin –” Clean Code”, Parson Education, Inc. 2008
  29. 29. 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.”
  30. 30. The “Must Read”-Book(s)by Krzysztof Cwalina, Brad Abrams Framework Design Guidelines “teaches developers the best practices for designing reusable libraries for the Microsoft .NET Framework.”
  31. 31. 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!)
  32. 32. Downloads, Feedback & Comments: Q & A Graphic by Nathan Sawaya courtesy of brickartist.com theo@designitright.net www.designitright.net www.speakerrate.com/theoj
  33. 33. References…http://clean-code-developer.com 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
  34. 34. … 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/ Fakes (Previous Moles & Pex) http://www.richonsoftware.com/post/2012/04/20/Comparing-Microsoft -Moles-in-Visual-Studio-2010-to-Microsoft-Fakes-in-Visual-Studio-11.aspx 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)
  35. 35. Blog, Rating, Slides http://www.DesignItRight.net www.speakerrate.com/theoj www.slideshare.net/theojungeblut
  36. 36. … thanks for you attention! And visit and support the www.sandiegodotnet.com Please fill out the feedback, and… www.speakerrate.com/theoj
  1. A particular slide catching your eye?

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

×