Clean Code for Bay.NET User Group (2011-03-02)

  • 2,073 views
Uploaded on

Bay.NET User Group South Bay Chapter presentation on Clean Code principles and best practices from March 3rd 2010.

Bay.NET User Group South Bay Chapter presentation on Clean Code principles and best practices from March 3rd 2010.

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
2,073
On Slideshare
0
From Embeds
0
Number of Embeds
2

Actions

Shares
Downloads
25
Comments
0
Likes
1

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. South Bay Clean CodeWhy Clean Code matters Mountain View, March 2nd 2011
  • 2. Theo Jungeblut• Senior Software Developer at Omnicell Inc. in Mountain View• Has been designing and implementing .NET based applications , components and frameworks for 8 years• Previously worked in factory automation with focus on component based software and framework development for 3 ½ years theo@csharp-lighthouse.com• Degree in Software Engineering and Network Communications www.csharp-lightouse.com
  • 3. Overview• Why Clean Code• Tools • Resharper • FxCop, StyleCop & StyleCop plugin for Resharper • GhostDoc & Spell Checker • Code Contracts, Pex & Moles• Clean Code Developer Initiative• Principles and Practices• Code Comparison• Q&A
  • 4. Does writing Clean Codemake us more efficient?
  • 5. What is Clean Code?
  • 6. http://www.technicopedia.com/8865.html
  • 7. http://www.technicopedia.com/8865.html
  • 8. http://technicbricks.blogspot.com/2009/06/tbs-techpoll-12-results-2009-1st.html
  • 9. .NET Tools and their ImpactTool name Positive Impact Negative ImpactResharper compiling -- -- -- VS responsiveness --FxCop code quality +++ compiling +StyleCop code quality compiling +StyleCop plugin compiling --- VS responsiveness --for ResharperGhost Doc automated docs potentially worse docSpell Checker fewer spelling errors performance --Code Contracts testability, quality +++ compiling ++Pex & Moles automated test limited
  • 10. Resharper“The single most impacting development addition to Visual Studio” Features: – Code Analysis – Code Templates – Code Generation – Code Cleanup – Many, many more… http://www.jetbrains.com/resharper/
  • 11. FxCop / Code AnalysisStatic Code Analysis: – Correctness – Library design – Internationalization and localization – Naming conventions – Performance – Security
  • 12. • Design-by-Contract programming• Improved testability• Static verification• API documentation http://msdn.microsoft.com/en-us/devlabs/dd491992
  • 13. Method OverviewCode Contracts User Manual, 5.3 Contract Ordering, page 22
  • 14. Runtime Checking LevelsCode Contracts User Manual, 6.2.1 Runtime Checking Level, page 24
  • 15. Argument ValidationCode Contracts User Manual,5.1 Argument Validation andContracts, page 18
  • 16. Microsoft Pex & Moles• Pex automatically generates test suites with high code coverage.• Moles allows to replace any .NET method with a delegate. http://research.microsoft.com/en-us/projects/pex/
  • 17. Ghost Doc• Save keystrokes and time• Simplify documenting your code• Benefit of the base class documentation http://submain.com/products/ghostdoc.aspx
  • 18. Spell Checker • Spelll chicking for texts and comments in VShttp://visualstudiogallery.msdn.microsoft.com/7c8341f1-ebac-40c8-92c2-476db8d523ce/
  • 19. Graphic by Michael Hönnig http://michael.hoennig.de/2009/08/08/clean-code-developer-ccd/
  • 20. Keep it simple, stupid (KISS)
  • 21. Graphic by Nathan Sawaya courtesy of brickartist.com
  • 22. Don’t repeat yourself (DRY)
  • 23. Separation of Concerns (SoC)Single Responsibility Principle (SRP)
  • 24. Component-Oriented Programming (CoP)
  • 25. Dependency Inversion Principle (DIP)
  • 26. 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
  • 27. Source Code Conventions
  • 28. Let’s switch to the code
  • 29. Summary Clean CodeBeing more efficient through:• Simplification and Specialization (KISS, SoC, SRP)• Decoupling (Contracts, CoP, IoC or SOA)• Avoiding Code Blow (DRY, YAGNI)• Quality through Testability (all of them!)
  • 30. Q&AGraphic by Nathan Sawaya courtesy of brickartist.com
  • 31. 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/StyleCop Plugin for Resharperhttp://stylecopforresharper.codeplex.com/Ghostdochttp://submain.com/products/ghostdoc.aspx Lego (trademarked in capitals as LEGO)
  • 32. gotowww.csharp-lighthouse.com for slides & code examples