Matchstick Men: A Serious Case Study in Code Quality
Transcription
Matchstick Men: A Serious Case Study in Code Quality
Matchstick Men: A Serious Case Study in Code Quality Chris Campbell, PhD Matchstick Men Doing Work • Confirmatory analysis should be well planned • Exploratory analysis may be more investigative Explore... with R scripts • What is possible? • How should it be achieved? What Next? Industrialization! • Mass production • Reduced costs What Next? Industrialization! • Mass production • Reduced costs • Reproducibility • Easier Quality Control ? http://www.econometricsbysimulation.com/ Doing Work draw.stick.R • low level plotting function to add matchstick men to plot Doing Work draw.stick.R • • • • refactored to a function documented with comments multipurpose tested Identify Units draw.stick.R drawStick.R addHead.R addArms.R addLegs.R Identify Units • Easier to: • Test • Maintain • Extend Enhance Documentation • Describe current behaviour • Provide examples • Note intended usage and exceptions roxygen2 roxygen2 • Awesome tool • Documenting as you go along is correct • Automated checks that all arguments are described roxygen2 • Yes, even you! Make Package Source > package.skeleton(name = "stick") Make Package Documentation > roxygenize("stick") Write Tests • Easier to: • Check code is correct! • Keep track of working cases • Keep track of error cases • Maintain • Extend testthat • Awesome tool • Testing as you go along is correct • Automatically run all tests • See also RUnit Examine Code • Code Review: • Double check code is correct! • Metrics for code quality • Ensure that code meets requirements TestCoverage > reportCoverage("stick") • Awesome tool • View tested components • Available 2014 functionMap • Awesome tool • View relationships between files • Available 2014 Quality • • • • • Requirements Make Code Do Thing Unit Test Code Examine Code for Improvements System Test Code