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

From Expertiza_Wiki
Jump to navigation Jump to search
Line 16: Line 16:
== Approach ==
== Approach ==
The approach we took to refactor this file, is to go through the issues generated by code climate and fix the smaller issues first. This gave us an idea about the code is doing and gave us a head start to fix bigger issues.
The approach we took to refactor this file, is to go through the issues generated by code climate and fix the smaller issues first. This gave us an idea about the code is doing and gave us a head start to fix bigger issues.
69 issues were found on code climate and Through this project, 30-35 issues have been resolved. Few of the issues that were resolved was detected by rubocop.
69 issues were found on code climate and through this project, 30-35 issues have been resolved. Few of the issues that were resolved was detected by rubocop.


== Refactoring longer methods ==
== Refactoring longer methods ==
We refactored the longer methods mostly using extract method. The methods refactored using Extract method are scores method and review_questionnaire_id method. The scores method was the biggest method in assignment.rb file. The scores methods computes and returns the scores of participants and teams as a hash. The participant scores and directly got by calling a method in participant. For the teams, there can two possibilities. Scores method has nested loop structures along with many lines code performing a distinct action inside the nested loop. Hence first we extracted a method performing from the inner most nested level
We refactored the longer methods mostly using extract method. The methods refactored using Extract method are scores method and review_questionnaire_id method. The scores method was the biggest method in assignment.rb file. The scores methods computes and returns the scores of participants and teams as a hash. The participant scores and directly got by calling a method in participant. For the teams, there can two possibilities. Scores method has nested loop structures along with many lines code performing a distinct action inside the nested loop. Hence first we extracted a method performing from the inner most nested level

Revision as of 21:53, 23 March 2020

Introduction

Expertiza allows instructors to add assignments and students to upload their submissions. The assignment.rb model file consists of some basic CRUD operations along with some methods which help calculate scores and export details etc. The goal of the project is to refactor assignment.rb file to follow good coding practices.


Refactoring assignment.rb

Some of the coding issues with the assignment.rb file are 1) Methods performing more than one tasks, resulting in long methods 2) Methods with many conditional branches with multiple conditions and loops resulting in increased cyclomatic and cognitive complexity 3) Dead code 4) No proper naming conventions in some places. 5) Large number of methods in one file.


Approach

The approach we took to refactor this file, is to go through the issues generated by code climate and fix the smaller issues first. This gave us an idea about the code is doing and gave us a head start to fix bigger issues. 69 issues were found on code climate and through this project, 30-35 issues have been resolved. Few of the issues that were resolved was detected by rubocop.

Refactoring longer methods

We refactored the longer methods mostly using extract method. The methods refactored using Extract method are scores method and review_questionnaire_id method. The scores method was the biggest method in assignment.rb file. The scores methods computes and returns the scores of participants and teams as a hash. The participant scores and directly got by calling a method in participant. For the teams, there can two possibilities. Scores method has nested loop structures along with many lines code performing a distinct action inside the nested loop. Hence first we extracted a method performing from the inner most nested level