CSC/ECE 517 Spring 2020 Refactor assignment.rb: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
Line 16: Line 16:
== [[Refactors]] ==
== [[Refactors]] ==


Added these constants to file:
  # Constants for common fields, to reduce complexity if change is needed
  FINISHED_CONST = 'Finished'.freeze
  UNKNOWN_CONST = 'Unknown'.freeze
(topic_id.nil? ? UNKNOWN_CONST : get_current_stage(topic_id))
due_date == FINISHED_CONST


== [[Testing]] ==
== [[Testing]] ==

Revision as of 19:29, 30 March 2020

Abstract

Expertiza is a web application using Ruby on Rails framework. The creation and maintenance of this application is handled by NCSU students and faculty. The basic functionalities allow the instructor to create and edit, both new and existing assignments. Also it allows the publishing of surveys and peer reviews, while allowing students the opportunity to sign up for topics, teams, submit assignments and peer reviews.

Problem Statement

Assignment.rb is a large file, that has dozens of methods and fields. Some methods seem redundant, and some fields and string literals are repeated multiple times throughout the file. Ie. 'Finished'. Each method in the file is essential and provides different data, so the goal for my team was to rename and merge code where we could, while not affecting the end functionality.


Problem Solution

Due to the fragile nature of the methods in Assignment.rb, our team decided to focus on redundancy in the code and anywhere we could merge redundant code into common methods. Also there were quite a few strings that were used constantly in the file, ie. 'Finished' that we decided to make constants, to reduce complexity if the values ever changed.


Refactors

Added these constants to file:

 # Constants for common fields, to reduce complexity if change is needed
 FINISHED_CONST = 'Finished'.freeze
 UNKNOWN_CONST = 'Unknown'.freeze


(topic_id.nil? ? UNKNOWN_CONST : get_current_stage(topic_id)) due_date == FINISHED_CONST

Testing