


He wasn’t confident that there was enough test coverage on the code he was changing and wanted a way to test with real datasets. Scientist was born when a former coworker, Rick Bradley, was trying to refactor a very complex API endpoint that returned long lists of repositories. InfoQ has spoken with Jesse Toth, principal engineer at GitHub.Ĭould you describe how Scientist was born? More advanced control options allow to ignore results, run more than one try block, or run only try blocks to cover special use cases. by defining a specific compare method to override the default = operator used to compare control and candidate outcomes, specifying a context that will be available when publishing the data, controlling setup tasks, enabling or disabling experiments execution, etc. Scientist provides a number of ways to customize its default behaviour, e.g. Besides comparing the result of try and use blocks, Scientist will also randomize the order of their execution to avoid any possible correlations, measure the duration of both executions, manage exceptions, and publish collected results. The publish method is called at the end of the experiment so collected data can be published. The run method will always return what the use block returns. experiment = Scientist::Default.new "my-experiment" The old path ensure that the system will continue working correctly during the whole trial period while the new path correctness is assessed.Īn experiment is a lightweight abstraction that provides two behaviours, a use behaviour meant to exercise the old path, and a try behaviour meant to exercise the new path. The basic idea brought about by Scientist is that of a controlled experiment whereby both the old path and the new path are stressed, then their outcomes compared, and any mismatches and/or exceptions logged. Furthermore, it tries to circumvent the limits of testing, which seldom can go so far as to cover all possible cases or input data combinations. Particularly, Scientist aims to provide a better guarantee than when using the BranchByAbstraction architectural pattern, which, though very useful in its own, merely ensures that the new component will be used wherever the old one was. Scientist, explains Toth, is particularly useful when refactoring critical code, that is when it is extremely important to reach confidence in the correctness of the new implementation. GitHub has just made available Scientist 1.0, a Ruby library that will help developers refactor or rewrite their code with confidence, writes GitHub engineer Jesse Toth. Scientist was used at GitHub over the last few years for a number of projects.
