CSC/ECE 517 Fall 2013/oss E814 vd: Difference between revisions
Line 1: | Line 1: | ||
Expertiza is a web application that supports peer-review for a variety of entities. As it is still evolving, expertiza has several areas that require work. Among these include areas that require refactoring existing code to improve code quality. The graph_generator.rb file is one such area. This write-up describes our refactoring decisions for this file. | Expertiza is a web application that supports peer-review for a variety of entities. As it is still evolving, expertiza has several areas that require work. Among these include areas that require refactoring existing code to improve code quality. The graph_generator.rb file is one such area. This write-up describes our refactoring decisions for this file. | ||
==Background== | ==Background== | ||
The graph_generator.rb file an automated metareview feature responsible for parsing the test from a review and creating a graph of the content. This file was plagued with several cases of duplication and a very high complexity. We attempted to identify areas in need of refactoring and fix as many of these areas as possible. | The graph_generator.rb file an automated metareview feature responsible for parsing the test from a review and creating a graph of the content. This file was plagued with several cases of duplication and a very high complexity. We attempted to identify areas in need of refactoring and fix as many of these areas as possible. In the rest of this page, we go method-by-method to describe our changes to the original file. After doing so, we describe the improvements (based on Code Climate's metrics) we achieved. Finally, we identify areas that proved quite problematic for our assignment. | ||
==Resources== | ==Resources== |
Revision as of 21:17, 30 October 2013
Expertiza is a web application that supports peer-review for a variety of entities. As it is still evolving, expertiza has several areas that require work. Among these include areas that require refactoring existing code to improve code quality. The graph_generator.rb file is one such area. This write-up describes our refactoring decisions for this file.
Background
The graph_generator.rb file an automated metareview feature responsible for parsing the test from a review and creating a graph of the content. This file was plagued with several cases of duplication and a very high complexity. We attempted to identify areas in need of refactoring and fix as many of these areas as possible. In the rest of this page, we go method-by-method to describe our changes to the original file. After doing so, we describe the improvements (based on Code Climate's metrics) we achieved. Finally, we identify areas that proved quite problematic for our assignment.
Resources
- Code Climate analysis of refactored file
- Code Climate analysis of original file
- Github repository for refactored project
- VCL location
Changes by Method
generate_graph
tagged_token_check
The first change that can be seen within this method is the extracting of code that adds on to a previous vertex or creates a new one, all based upon the part of speech defined of the tokens encountered while parsing the review. We called our extracted method tagged_token_check. BY extracting this method, we were able to reduce duplication (since such similar code occurred four times in the method for tokens that are nouns, adjectives, adverbs, and verbs. Since the code contained nested if statements, we also were able to reduce the complexity of the method. Screenshots of the code before and after refactoring are included below. The top picture is the code before refactoring, the middle is the code after, and the bottom is the code within the extracted method.
update_pos_property
The next change in generate_graph
pos_edge_processing
add_nonexisting_edge
remove_redundant_edges
The remove_redundant_edges method also suffered from high code complexity, so we extracted a new method called find_redundant_edges to reduce such complexity. The screenshots below show the contents of the original code (on top) and the extracted method code (on the bottom).