clean code part iii - craftsmanship at socal code camp

Download Clean Code Part III - Craftsmanship at SoCal Code Camp

Post on 29-Nov-2014

1.426 views

Category:

Technology

1 download

Embed Size (px)

DESCRIPTION

When building a house, good architecture and craftsmanship together form the needed crucial elements for success. The same pattern applies to software development. As the previous sessions focused on the architectural part of software development, this session will strongly focus on often forgotten but very important areas of coding. 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 2010. However, the demonstrated patterns and practice can be applied to every other programming language too.

TRANSCRIPT

  • 1. SolCal CodeCampClean Code IIISoftware CraftsmanshipSan Diego, June 24rd 2012

2. Theo Jungeblut Senior Software Developer atAppDynamics in San Francisco architects decoupled solutionstailored to business needs and craftsmaintainable code to last worked in healthcare and factoryautomation, building mission criticalapplications, framework &platforms for 8+ years degree in Software Engineeringand Network Communicationstheo@designitright.net enjoys cycling, running and eatingwww.designitright.netwww.speakerrate.com/theoj 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. Does writing Clean Codemake us more efficient? 5. What is Clean Code? 6. Clean Code is maintainable Source code must be: readable & well structured extensible testable 7. Software Engineeringvs.Craftsmanship 8. Software Engineering ANDCraftsmanship 9. The Must Read-Book(s) by Robert C MartinA Handbook of AgileSoftwareCraftsmanshipEven bad code canfunction. But if codeisnt clean, it can bring adevelopmentorganization to itsknees. 10. Code Maintainability *Principles Patterns Containers Why?How?What?ExtensibilityClean Code Tool reuse* from: Mark Seemanns Dependency Injection in .NET presentation Bay.NET 05/2011 11. Keep it simple, stupid(KISS) 12. KISS-Principle Keep It Simple Stupid by Kelly Johnsonhttp://blogs.smarter.com/blogs/Lego%20Brick.jpg 13. The Power of Simplicity Graphic by Nathan Sawaya courtesy of brickartist.comGraphic by Nathan Sawaya courtesy of brickartist.comhttp://www.geekalerts.com/lego-iphone/ 14. Graphic by Nathan Sawaya courtesy of brickartist.com 15. Source Code Conventions 16. .NET Tools and their ImpactTool namePositive Impact Negative ImpactResharpercompiling ++++VS responsiveness --FxCopcode quality ++ compiling time -StyleCop code consistency +++compiling time -StyleCop plugin compiling time +++ VS responsiveness --for ResharperGhost Docautomated docspotentially worse docSpell Checkerfewer spelling errors ++ performance --Code Contracts testability, quality ++ compiling time --Pex & Molesautomated test ++ compiling time -- 17. ResharperThe single most impacting developmentaddition to Visual Studio Features: Code Analysis Quick Fixes Code Templates Code Generation Code Cleanup Many, many morehttp://www.jetbrains.com/resharper/ 18. FxCop / Static Code AnalysisCode Analysis: Correctness Library design Internationalization and localization Naming conventions Performance Securityhttp://msdn.microsoft.com/en-us/library/3z0aeatx.aspx 19. 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 20. Ghost Doc Save keystrokes and time Simplify documenting your code Benefit of the base class documentationhttp://submain.com/products/ghostdoc.aspx 21. Spell Checker Spelll chicking for literals and comments in VShttp://visualstudiogallery.msdn.microsoft.com/7c8341f1-ebac-40c8-92c2-476db8d523ce/ 22. Design-by-Contract programming Improved testability Static verification API documentation integration withSandcastlehttp://msdn.microsoft.com/en-us/devlabs/dd491992 23. Microsoft Pex & Moles Pex automatically generates test suites withhigh code coverage. Moles allows to replace any .NET method witha delegate.http://research.microsoft.com/en-us/projects/pex/ 24. Names Matter Meaningful Names Intention Revealing Names Use Pronounceable Names Use Searchable Names Avoid Encoding (Hungarian) Dont be cute Pick One Word per Concept Use Problem Domain Names* Chapter extract: Robert C. Martin Clean Code, Parson Education, Inc. 2008 25. Functions Small Do One Thing One Level of Abstraction No or only few Arguments Have No Side Effects Prefer Exceptions to Returning Error Codes Dont Repeat Yourself* Chapter extract: Robert C. Martin Clean Code, Parson Education, Inc. 2008 26. Comments Comments o 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 27. Bad Comments Mumblings Redundant Comments Misleading Comments Journal Comments Noise Comments Dont 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 28. 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 29. 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 30. The Must Read-Book(s) by Robert C MartinA Handbook of AgileSoftwareCraftsmanshipEven bad code canfunction. But if codeisnt clean, it can bring adevelopmentorganization to itsknees. 31. TheKrzysztof Cwalina,Read-Book(s)by Must Brad AbramsFramework DesignGuidelinesteachesdevelopers thebest practices fordesigning reusablelibraries for theMicrosoft .NETFramework. 32. 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!) 33. Q&A Downloads, Feedback & Comments: theo@designitright.net www.designitright.net www.speakerrate.com/theojGraphic by Nathan Sawaya courtesy of brickartist.com 34. http://clean-code-developer.comReferenceshttp://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 35. 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) 36. Please fill out thefeedback, andwww.speakerrate.com/theoj thanks for you attention!And visit and support thewww.sandiegodotnet.com