SlideShare uma empresa Scribd logo
1 de 36
Baixar para ler offline
South Bay


  Clean Code
Why Clean Code matters

   Mountain View, March 2nd 2011
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
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
Does writing Clean Code
make us more efficient?
What is Clean Code?
http://www.technicopedia.com/8865.html
http://www.technicopedia.com/8865.html
http://technicbricks.blogspot.com/2009/06/tbs-techpoll-12-results-2009-1st.html
.NET Tools and their Impact
Tool name        Positive Impact            Negative Impact
Resharper        compiling -- -- --         VS responsiveness --
FxCop            code quality +++           compiling +
StyleCop         code quality               compiling +
StyleCop plugin compiling ---               VS responsiveness --
for Resharper
Ghost Doc        automated docs             potentially worse doc
Spell Checker    fewer spelling errors      performance --
Code Contracts   testability, quality +++   compiling ++
Pex & Moles      automated test             limited
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/
FxCop / Code Analysis
Static Code Analysis:
  – Correctness
  – Library design
  – Internationalization and localization
  – Naming conventions
  – Performance
  – Security
•   Design-by-Contract programming
•   Improved testability
•   Static verification
•   API documentation

    http://msdn.microsoft.com/en-us/devlabs/dd491992
Method Overview




Code Contracts User Manual, 5.3 Contract Ordering, page 22
Runtime Checking Levels




Code Contracts User Manual, 6.2.1 Runtime Checking Level, page 24
Argument Validation




Code Contracts User Manual,
5.1 Argument Validation and
Contracts, page 18
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/
Ghost Doc

• Save keystrokes and time
• Simplify documenting your code
• Benefit of the base class documentation




          http://submain.com/products/ghostdoc.aspx
Spell Checker

  • Spelll chicking for texts and comments in VS




http://visualstudiogallery.msdn.microsoft.com/7c8341f1-ebac-40c8-92c2-476db8d523ce/
Graphic by Michael Hönnig http://michael.hoennig.de/2009/08/08/clean-code-developer-ccd/
Keep it simple, stupid
        (KISS)
Graphic by Nathan Sawaya courtesy of brickartist.com
Don’t repeat yourself
        (DRY)
Separation of Concerns (SoC)

Single Responsibility Principle (SRP)
Component-Oriented
   Programming
       (CoP)
Dependency Inversion Principle
           (DIP)
S               Single Responsibility Principle

   O               Open/Closed Principle

   L               Liskov Substitution Principle

   I               Interface Segregation Principle

   D               Dependency Inversion Principle

Robert C Martin:   http://butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod
Source Code Conventions
Let’s switch to the code
Summary Clean Code
Being 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!)
Q&A




Graphic by Nathan Sawaya courtesy of brickartist.com
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/

Pex & Mole
http://research.microsoft.com/en-us/projects/pex/

StyleCop
http://stylecop.codeplex.com/

StyleCop Plugin for Resharper
http://stylecopforresharper.codeplex.com/

Ghostdoc
http://submain.com/products/ghostdoc.aspx
                                                               Lego (trademarked in capitals as LEGO)
goto

www.csharp-lighthouse.com

           for

  slides & code examples

Mais conteúdo relacionado

Mais de Theo Jungeblut

Clean Code - Design Patterns and Best Practices at Silicon Valley Code Camp
Clean Code - Design Patterns and Best Practices at Silicon Valley Code CampClean Code - Design Patterns and Best Practices at Silicon Valley Code Camp
Clean Code - Design Patterns and Best Practices at Silicon Valley Code CampTheo Jungeblut
 
Debugging,Troubleshooting & Monitoring Distributed Web & Cloud Applications a...
Debugging,Troubleshooting & Monitoring Distributed Web & Cloud Applications a...Debugging,Troubleshooting & Monitoring Distributed Web & Cloud Applications a...
Debugging,Troubleshooting & Monitoring Distributed Web & Cloud Applications a...Theo Jungeblut
 
Clean Code III - Software Craftsmanship at SoCal Code Camp San Diego (07/27/2...
Clean Code III - Software Craftsmanship at SoCal Code Camp San Diego (07/27/2...Clean Code III - Software Craftsmanship at SoCal Code Camp San Diego (07/27/2...
Clean Code III - Software Craftsmanship at SoCal Code Camp San Diego (07/27/2...Theo Jungeblut
 
Clean Code II - Dependency Injection at SoCal Code Camp San Diego (07/27/2013)
Clean Code II - Dependency Injection at SoCal Code Camp San Diego (07/27/2013)Clean Code II - Dependency Injection at SoCal Code Camp San Diego (07/27/2013)
Clean Code II - Dependency Injection at SoCal Code Camp San Diego (07/27/2013)Theo Jungeblut
 
Clean Code I - Design Patterns and Best Practices at SoCal Code Camp San Dieg...
Clean Code I - Design Patterns and Best Practices at SoCal Code Camp San Dieg...Clean Code I - Design Patterns and Best Practices at SoCal Code Camp San Dieg...
Clean Code I - Design Patterns and Best Practices at SoCal Code Camp San Dieg...Theo Jungeblut
 
Cut your Dependencies with Dependency Injection for East Bay.NET User Group
Cut your Dependencies with Dependency Injection for East Bay.NET User Group Cut your Dependencies with Dependency Injection for East Bay.NET User Group
Cut your Dependencies with Dependency Injection for East Bay.NET User Group Theo Jungeblut
 
Clean Code - Design Patterns and Best Practices for Bay.NET SF User Group (01...
Clean Code - Design Patterns and Best Practices for Bay.NET SF User Group (01...Clean Code - Design Patterns and Best Practices for Bay.NET SF User Group (01...
Clean Code - Design Patterns and Best Practices for Bay.NET SF User Group (01...Theo Jungeblut
 
Cut your Dependencies with Dependency Injection - .NET User Group Osnabrueck
Cut your Dependencies with Dependency Injection - .NET User Group OsnabrueckCut your Dependencies with Dependency Injection - .NET User Group Osnabrueck
Cut your Dependencies with Dependency Injection - .NET User Group OsnabrueckTheo Jungeblut
 
Cut your Dependencies - Dependency Injection at Silicon Valley Code Camp
Cut your Dependencies - Dependency Injection at Silicon Valley Code CampCut your Dependencies - Dependency Injection at Silicon Valley Code Camp
Cut your Dependencies - Dependency Injection at Silicon Valley Code CampTheo Jungeblut
 
Clean Code Part III - Craftsmanship at SoCal Code Camp
Clean Code Part III - Craftsmanship at SoCal Code CampClean Code Part III - Craftsmanship at SoCal Code Camp
Clean Code Part III - Craftsmanship at SoCal Code CampTheo Jungeblut
 
Clean Code Part II - Dependency Injection at SoCal Code Camp
Clean Code Part II - Dependency Injection at SoCal Code CampClean Code Part II - Dependency Injection at SoCal Code Camp
Clean Code Part II - Dependency Injection at SoCal Code CampTheo Jungeblut
 
Clean Code Part I - Design Patterns at SoCal Code Camp
Clean Code Part I - Design Patterns at SoCal Code CampClean Code Part I - Design Patterns at SoCal Code Camp
Clean Code Part I - Design Patterns at SoCal Code CampTheo Jungeblut
 
Clean Code for East Bay .NET User Group
Clean Code for East Bay .NET User GroupClean Code for East Bay .NET User Group
Clean Code for East Bay .NET User GroupTheo Jungeblut
 
Contract First Development with Microsoft Code Contracts and Microsoft Pex at...
Contract First Development with Microsoft Code Contracts and Microsoft Pex at...Contract First Development with Microsoft Code Contracts and Microsoft Pex at...
Contract First Development with Microsoft Code Contracts and Microsoft Pex at...Theo Jungeblut
 
Lego For Engineers - Dependency Injection for LIDNUG (2011-06-03)
Lego For Engineers - Dependency Injection for LIDNUG (2011-06-03)Lego For Engineers - Dependency Injection for LIDNUG (2011-06-03)
Lego For Engineers - Dependency Injection for LIDNUG (2011-06-03)Theo Jungeblut
 
Lego for Software Engineers at Silicon Valley Code Camp 2011 (2010-10-10)
Lego for Software Engineers at Silicon Valley Code Camp 2011 (2010-10-10)Lego for Software Engineers at Silicon Valley Code Camp 2011 (2010-10-10)
Lego for Software Engineers at Silicon Valley Code Camp 2011 (2010-10-10)Theo Jungeblut
 

Mais de Theo Jungeblut (16)

Clean Code - Design Patterns and Best Practices at Silicon Valley Code Camp
Clean Code - Design Patterns and Best Practices at Silicon Valley Code CampClean Code - Design Patterns and Best Practices at Silicon Valley Code Camp
Clean Code - Design Patterns and Best Practices at Silicon Valley Code Camp
 
Debugging,Troubleshooting & Monitoring Distributed Web & Cloud Applications a...
Debugging,Troubleshooting & Monitoring Distributed Web & Cloud Applications a...Debugging,Troubleshooting & Monitoring Distributed Web & Cloud Applications a...
Debugging,Troubleshooting & Monitoring Distributed Web & Cloud Applications a...
 
Clean Code III - Software Craftsmanship at SoCal Code Camp San Diego (07/27/2...
Clean Code III - Software Craftsmanship at SoCal Code Camp San Diego (07/27/2...Clean Code III - Software Craftsmanship at SoCal Code Camp San Diego (07/27/2...
Clean Code III - Software Craftsmanship at SoCal Code Camp San Diego (07/27/2...
 
Clean Code II - Dependency Injection at SoCal Code Camp San Diego (07/27/2013)
Clean Code II - Dependency Injection at SoCal Code Camp San Diego (07/27/2013)Clean Code II - Dependency Injection at SoCal Code Camp San Diego (07/27/2013)
Clean Code II - Dependency Injection at SoCal Code Camp San Diego (07/27/2013)
 
Clean Code I - Design Patterns and Best Practices at SoCal Code Camp San Dieg...
Clean Code I - Design Patterns and Best Practices at SoCal Code Camp San Dieg...Clean Code I - Design Patterns and Best Practices at SoCal Code Camp San Dieg...
Clean Code I - Design Patterns and Best Practices at SoCal Code Camp San Dieg...
 
Cut your Dependencies with Dependency Injection for East Bay.NET User Group
Cut your Dependencies with Dependency Injection for East Bay.NET User Group Cut your Dependencies with Dependency Injection for East Bay.NET User Group
Cut your Dependencies with Dependency Injection for East Bay.NET User Group
 
Clean Code - Design Patterns and Best Practices for Bay.NET SF User Group (01...
Clean Code - Design Patterns and Best Practices for Bay.NET SF User Group (01...Clean Code - Design Patterns and Best Practices for Bay.NET SF User Group (01...
Clean Code - Design Patterns and Best Practices for Bay.NET SF User Group (01...
 
Cut your Dependencies with Dependency Injection - .NET User Group Osnabrueck
Cut your Dependencies with Dependency Injection - .NET User Group OsnabrueckCut your Dependencies with Dependency Injection - .NET User Group Osnabrueck
Cut your Dependencies with Dependency Injection - .NET User Group Osnabrueck
 
Cut your Dependencies - Dependency Injection at Silicon Valley Code Camp
Cut your Dependencies - Dependency Injection at Silicon Valley Code CampCut your Dependencies - Dependency Injection at Silicon Valley Code Camp
Cut your Dependencies - Dependency Injection at Silicon Valley Code Camp
 
Clean Code Part III - Craftsmanship at SoCal Code Camp
Clean Code Part III - Craftsmanship at SoCal Code CampClean Code Part III - Craftsmanship at SoCal Code Camp
Clean Code Part III - Craftsmanship at SoCal Code Camp
 
Clean Code Part II - Dependency Injection at SoCal Code Camp
Clean Code Part II - Dependency Injection at SoCal Code CampClean Code Part II - Dependency Injection at SoCal Code Camp
Clean Code Part II - Dependency Injection at SoCal Code Camp
 
Clean Code Part I - Design Patterns at SoCal Code Camp
Clean Code Part I - Design Patterns at SoCal Code CampClean Code Part I - Design Patterns at SoCal Code Camp
Clean Code Part I - Design Patterns at SoCal Code Camp
 
Clean Code for East Bay .NET User Group
Clean Code for East Bay .NET User GroupClean Code for East Bay .NET User Group
Clean Code for East Bay .NET User Group
 
Contract First Development with Microsoft Code Contracts and Microsoft Pex at...
Contract First Development with Microsoft Code Contracts and Microsoft Pex at...Contract First Development with Microsoft Code Contracts and Microsoft Pex at...
Contract First Development with Microsoft Code Contracts and Microsoft Pex at...
 
Lego For Engineers - Dependency Injection for LIDNUG (2011-06-03)
Lego For Engineers - Dependency Injection for LIDNUG (2011-06-03)Lego For Engineers - Dependency Injection for LIDNUG (2011-06-03)
Lego For Engineers - Dependency Injection for LIDNUG (2011-06-03)
 
Lego for Software Engineers at Silicon Valley Code Camp 2011 (2010-10-10)
Lego for Software Engineers at Silicon Valley Code Camp 2011 (2010-10-10)Lego for Software Engineers at Silicon Valley Code Camp 2011 (2010-10-10)
Lego for Software Engineers at Silicon Valley Code Camp 2011 (2010-10-10)
 

Último

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 

Último (20)

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 

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

  • 1. South Bay Clean Code Why 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 Code make us more efficient?
  • 5.
  • 7.
  • 11. .NET Tools and their Impact Tool name Positive Impact Negative Impact Resharper compiling -- -- -- VS responsiveness -- FxCop code quality +++ compiling + StyleCop code quality compiling + StyleCop plugin compiling --- VS responsiveness -- for Resharper Ghost Doc automated docs potentially worse doc Spell Checker fewer spelling errors performance -- Code Contracts testability, quality +++ compiling ++ Pex & Moles automated test limited
  • 12. 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/
  • 13. FxCop / Code Analysis Static Code Analysis: – Correctness – Library design – Internationalization and localization – Naming conventions – Performance – Security
  • 14. Design-by-Contract programming • Improved testability • Static verification • API documentation http://msdn.microsoft.com/en-us/devlabs/dd491992
  • 15. Method Overview Code Contracts User Manual, 5.3 Contract Ordering, page 22
  • 16. Runtime Checking Levels Code Contracts User Manual, 6.2.1 Runtime Checking Level, page 24
  • 17. Argument Validation Code Contracts User Manual, 5.1 Argument Validation and Contracts, page 18
  • 18.
  • 19. 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/
  • 20. Ghost Doc • Save keystrokes and time • Simplify documenting your code • Benefit of the base class documentation http://submain.com/products/ghostdoc.aspx
  • 21. Spell Checker • Spelll chicking for texts and comments in VS http://visualstudiogallery.msdn.microsoft.com/7c8341f1-ebac-40c8-92c2-476db8d523ce/
  • 22. Graphic by Michael Hönnig http://michael.hoennig.de/2009/08/08/clean-code-developer-ccd/
  • 23. Keep it simple, stupid (KISS)
  • 24. Graphic by Nathan Sawaya courtesy of brickartist.com
  • 26. Separation of Concerns (SoC) Single Responsibility Principle (SRP)
  • 27. Component-Oriented Programming (CoP)
  • 29. S Single Responsibility Principle O Open/Closed Principle L Liskov Substitution Principle I Interface Segregation Principle D Dependency Inversion Principle Robert C Martin: http://butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod
  • 31.
  • 32. Let’s switch to the code
  • 33. Summary Clean Code Being 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!)
  • 34. Q&A Graphic by Nathan Sawaya courtesy of brickartist.com
  • 35. 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/ Pex & Mole http://research.microsoft.com/en-us/projects/pex/ StyleCop http://stylecop.codeplex.com/ StyleCop Plugin for Resharper http://stylecopforresharper.codeplex.com/ Ghostdoc http://submain.com/products/ghostdoc.aspx Lego (trademarked in capitals as LEGO)
  • 36. goto www.csharp-lighthouse.com for slides & code examples