ITCamp 2013 - Florin Coros - Driving Your Team Towards Code Quality

236 views

Published on

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
236
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

ITCamp 2013 - Florin Coros - Driving Your Team Towards Code Quality

  1. 1. itcampro@ itcamp13# Premium conference on Microsoft technologiesDriving Your Team TowardsCode QualityFlorin Coroswww.rabs.roflorin.coros@rabs.ro@florincoroswww.florincoros.wordpress.com
  2. 2. itcampro@ itcamp13# Premium conference on Microsoft technologiesArchitecture &Best PracticesHuge thanks to our sponsors!
  3. 3. itcampro@ itcamp13# Premium conference on Microsoft technologiesArchitecture &Best PracticesAbout meRABS, Co-FounderISDC, Software Architect@florincoros
  4. 4. itcampro@ itcamp13# Premium conference on Microsoft technologiesArchitecture &Best PracticesInspired
  5. 5. itcampro@ itcamp13# Premium conference on Microsoft technologiesArchitecture &Best PracticesWhy Code Quality?
  6. 6. itcampro@ itcamp13# Premium conference on Microsoft technologiesArchitecture &Best PracticesChange Predictability- How much time to add this new small feature?- Hm… let’s see… so it is very similar with what we have, right? Hm… about 2 to 3 days I think...
  7. 7. itcampro@ itcamp13# Premium conference on Microsoft technologiesArchitecture &Best PracticesChange Predictabilitycrap…. I have to change much more than I thought … No way I can do this by tomorrow… I think I’m going to work on this 2 to 3 weeks maybe
  8. 8. itcampro@ itcamp13# Premium conference on Microsoft technologiesArchitecture &Best PracticesIt works. Don’t touch it!
  9. 9. itcampro@ itcamp13# Premium conference on Microsoft technologiesArchitecture &Best PracticesGood Design vs Bad Designhttp://martinfowler.com/bliki/DesignStaminaHypothesis.html
  10. 10. itcampro@ itcamp13# Premium conference on Microsoft technologiesArchitecture &Best PracticesTechnical Debt
  11. 11. itcampro@ itcamp13# Premium conference on Microsoft technologiesArchitecture &Best PracticesFunctions, Classes, Modules
  12. 12. itcampro@ itcamp13# Premium conference on Microsoft technologiesArchitecture &Best PracticesDesigns1 23 4http://channel9.msdn.com/Events/TechEd/NorthAmerica/2010/ARC201
  13. 13. itcampro@ itcamp13# Premium conference on Microsoft technologiesArchitecture &Best PracticesDesignshttp://channel9.msdn.com/Events/TechEd/NorthAmerica/2010/ARC201
  14. 14. itcampro@ itcamp13# Premium conference on Microsoft technologiesArchitecture &Best PracticesDesign Principles & Design Patterns
  15. 15. itcampro@ itcamp13# Premium conference on Microsoft technologiesArchitecture &Best PracticesKnowledge vs ExperienceYou learn the rules of chess in a few hoursYou become a good chess player after yearsof practicingYou need to practice with strong opponentsYou need to go to tournaments to meetstrong opponentsYou learn the rules of GO in a few minutesYou become a good GO player after manyyears of practicingSame as at chess, but much more exerciseis needed because it is more complex
  16. 16. itcampro@ itcamp13# Premium conference on Microsoft technologiesArchitecture &Best PracticesAlternative: GOOD Unit TestsIt is very smallIt can be written easily and runsquicklyIt’s readable, maintainable,trustworthy and fully automatedIt should run in isolationIt should test ONE thingIf it fails you should know exactlywhere the bug is
  17. 17. itcampro@ itcamp13# Premium conference on Microsoft technologiesArchitecture &Best PracticesHow does GOOD UT get us there?OOD PrinciplesSOLIDDRYIoC & DILowCouplingHigh Coherence…..…Design PatternsCompositeChain Of ResponsibilityDecorator…….Can you TEST it?Good EnoughGOOD Unit TestsSmallIn IsolationTest ONE ThingEasy to implement
  18. 18. itcampro@ itcamp13# Premium conference on Microsoft technologiesArchitecture &Best PracticesGood Unit Tests - easy to writeless than 5 minutes to implementfew lines of code. Less than 10 -15see from a glimpse what the test checks
  19. 19. itcampro@ itcamp13# Premium conference on Microsoft technologiesArchitecture &Best PracticesGood Unit Tests - Run in IsolationIsolate the code under testfrom the rest of your system,by creating seams, to be ableto plug fakes (stubs & mocks)which you can control inyour test“There is no object-orientedproblem that cannot besolved by adding a layer ofindirection, except, ofcourse, too many layers ofindirection.”
  20. 20. itcampro@ itcamp13# Premium conference on Microsoft technologiesArchitecture &Best PracticesGood Unit Test - test ONE thingCheck only ONE thing inyour tests. If the test failsyou know exactly where theproblem is. You do not needto do step-by-stepdebugging
  21. 21. itcampro@ itcamp13# Premium conference on Microsoft technologiesArchitecture &Best PracticesGood Unit Tests - not integration testsBCf()g()h()h’()Depend on abstractions not on implementationdetails (DIP)Use IoC for instantiating objects, or Factorydesign patternsVisible dependencies for our classesLow coupling and high coherenceExtensibility, Reusability (OCP)Design PatternsIntegration tests:HIGH COSTS & LOW BENEFITS
  22. 22. itcampro@ itcamp13# Premium conference on Microsoft technologiesArchitecture &Best PracticesGood Unit Tests - not integration testsScreenKeyboardtranslate()write()read()Depend on abstractions not on implementationdetails (DIP)Use IoC for instantiating objects, or Factorydesign patternsVisible dependencies for our classesLow coupling and high coherenceExtensibility, Reusability (OCP)Design PatternsIntegration tests:HIGH COSTS & LOW BENEFITS
  23. 23. itcampro@ itcamp13# Premium conference on Microsoft technologiesArchitecture &Best PracticesGood Unit Tests - not integration testsITextOutputITextInputtranslate()write()read()Depend on abstractions not on implementationdetails (DIP)Use IoC for instantiating objects, or Factorydesign patternsVisible dependencies for our classesLow coupling and high coherenceExtensibility, Reusability (OCP)Design PatternsIntegration tests:HIGH COSTS & LOW BENEFITS
  24. 24. itcampro@ itcamp13# Premium conference on Microsoft technologiesArchitecture &Best PracticesEliminate circular dependenciesA simple designed systemcannot be largeIt has low coupling and highcoherence
  25. 25. itcampro@ itcamp13# Premium conference on Microsoft technologiesArchitecture &Best PracticesEliminate circular dependenciesA system is large and too rigid tochange if it has circulardependenciesIt has high coupling and lowcoherence
  26. 26. itcampro@ itcamp13# Premium conference on Microsoft technologiesArchitecture &Best PracticesContinuous & Small CyclesCODEUNITTESTREFACTORShort cycles between unit test andproduction codeRefactor in early stage, at lower costsSame principle for test first or forcode first
  27. 27. itcampro@ itcamp13# Premium conference on Microsoft technologiesArchitecture &Best PracticesCode Coverage History9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29Infrastructure 30 35 40 41 60 70 70 75 75 76 79 78 80 68 70 71 65 71 65 70 68CoreServices 60 75 80 81 78 80 81 78 75 81 89 78 75 80 68 75 80 78 81 79 80Module 1 0 30 40 45 50 60 58 60 57 55 60 58 60 61 57 55 50 48 42 57 59Module 2 50 60 65 70 68 67 75 77 75 74 73 75 77 75 73 75 72 74 75 77 750102030405060708090100%BlocksCovered
  28. 28. itcampro@ itcamp13# Premium conference on Microsoft technologiesArchitecture &Best PracticesIs it easier?OOD PrinciplesDesign Patterns Can you TEST it?ReusabilityExtensibilityMaintainabilityGOOD Unit TestsBad Design Smells with Good TestsCode at wrong level of abstractionClass with more responsibilitiesBase classes depending on their derivatesArtificial couplingFeature envyPolymorphism over if/else or switch/casePoor coheranceViolates SOLIDShould have used certain design patternTest is difficult to understand. It is very large(more than 20 lines)Checks on more than ONE thingDoes not run in isolationAre not following the naming conventions
  29. 29. itcampro@ itcamp13# Premium conference on Microsoft technologiesArchitecture &Best PracticesHow to do it?ArchitectureApp SoftwareInfrastructureVertical SliceReviewGood UTRefactorWHOLE team is doing Good Unit Testing!DeliverFunctionalityDeliverFunctionalityDeliverFunctionalityDefine code coveragetargets
  30. 30. itcampro@ itcamp13# Premium conference on Microsoft technologiesArchitecture &Best PracticesThank you!

×