Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: refactor to improve readability of main_page function #230

Merged
merged 11 commits into from
Nov 16, 2020
Merged

fix: refactor to improve readability of main_page function #230

merged 11 commits into from
Nov 16, 2020

Conversation

priime0
Copy link
Contributor

@priime0 priime0 commented Nov 9, 2020

When initially browsing through the codebase, it was very difficult to grasp what all the lines of code were doing. I took the time to move verbose blocks of code into functions whose names hopefully describe what they were doing. By representing these blocks with single-line functions, it makes it easier to understand what the main_page function is trying to do, and thus less intimidating to contribute to.

I additionally rebased my commits to make their subject lines more consistent with one another, and in doing so, accidentally made myself a contributor to the 9eceaf4 commit, so ignore that. My commit messages further detail my line of reasoning for specific chunks in the code.

gary-kim-bot and others added 9 commits November 9, 2020 09:28
Signed-off-by: Gary Kim Bot <bot@garykim.dev>
By delegating the tasks to helper functions, the code becomes marginally
easier to browse through. Better function name could be selected,
however.

getStudentName has better readability than what was previously used, and
conveys its function better.

s1col and s2col were renamed to sem1_col and sem2_col respectively. This
is because "sem" is more understandable than "s".

Assigning values to sem1_col and sem2_col was put into a function.
Checking whether it was the second semester was also put into a
function. Initially both of these tasks were mashed together, but
separating it into two functions hopefully provides more clarity and
modularity.

I added newlines to the import statement from helpers because I
initially put the getSemesterCols and isSecondSemester functions in
there, but those changes aren't necessary.

Signed-off-by: Lucas Sta Maria <lucas.stamaria@gmail.com>
When reading the code in the main_page function, a headache can be
caused from the amount of jQuery code that has to be traversed. In
continuation of solving this problem, I have moved some of the code into
more descriptive functions.

The showCurrentGPA function is more descriptive than random jQuery.

The showfirstSemGPA function is also more descriptive than a fetch for
the HTML and a lot of HTML parsing and then finally displaying the GPA.

The getFirstSemCourses function is *hopefully* more descriptive than
fetch("https://powerschool.sas.edu.sg/guardian/termgrades.html").
There's probably a better function name for this.

By moving some of the code into the main_page function, it hopefully
creates better readability of the main_page function.

Signed-off-by: Lucas Sta Maria <lucas.stamaria@gmail.com>
Again, aiming for clarity in the main_page function. Wrapping the if
statement's very long jQuery parse into a function name that's in
English makes the code easier on the eyes.

Signed-off-by: Lucas Sta Maria <lucas.stamaria@gmail.com>
getCourses is a bit misleading considering it also adds a new class
grade, however, conveys the point better than it collects the user's
courses.

I additionally made the variables at the start of main_page constant
because there is no reason they should change after the function call.

Making these changes improves readability of the code, better conveying
what portions of it are doing.

Signed-off-by: Lucas Sta Maria <lucas.stamaria@gmail.com>
Again just moving code into functions for better readability.

Signed-off-by: Lucas Sta Maria <lucas.stamaria@gmail.com>
Easier to comprehend with a single function name rather than a series of
DOM modifications.

Signed-off-by: Lucas Sta Maria <lucas.stamaria@gmail.com>
`sem1_col` and `sem2_col` were initially undefined in this function.
Adding parameters for them and passing them as arguments fixes this.

I additionally fixed whitespace issues identified by the CI/CD pipeline.

Signed-off-by: Lucas Sta Maria <lucas.stamaria@gmail.com>
There were extra spaces at the end of lines, and some tabs were missing
before some lines. This resolves that issue.

Signed-off-by: Lucas Sta Maria <lucas.stamaria@gmail.com>
@gary-kim gary-kim added the enhancement Improvement to a feature label Nov 11, 2020
Gary recommended this change. A lot more condensed.

Signed-off-by: Lucas Sta Maria <lucas.stamaria@gmail.com>
Copy link
Member

@Suhas-13 Suhas-13 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like hypothetical assignment breaks with this, generates a value of NaN regardless of what percent / grade is used.

addHypoAssignment takes in an argument for the current final percent of
the student, but no argument was actually passed. This commit fixes that
by actually passing the argument.

This bug was caught by Suhas.

Signed-off-by: Lucas Sta Maria <lucas.stamaria@gmail.com>
@Suhas-13 Suhas-13 merged commit c1bf0f7 into sas-fossdev:master Nov 16, 2020
@Suhas-13 Suhas-13 added this to the Open Beta v0.22.0 milestone Nov 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvement to a feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants