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

Reduce code repetition #758

Open
raklaptudirm opened this issue Oct 8, 2021 · 9 comments
Open

Reduce code repetition #758

raklaptudirm opened this issue Oct 8, 2021 · 9 comments
Labels
beginner-friendly Easy to implement code quality Code quality improvement help wanted Needs to be worked on

Comments

@raklaptudirm
Copy link
Member

raklaptudirm commented Oct 8, 2021

We have now successfully added guidelines for importing and using algorithms in this repository, inside other algorithms. This has been done to reduce code repetition and uphold code quality. Some functions do implement their own versions of data structures and helper functions, as previously, algorithms were supposed to be completely self contained. This issue initiates a search and fix so that all functions and data structures which can be imported in an algorithm should be imported.

Also as an addition to the topic, this initiative should also weed out bad code, i.e.:

  • Code which does not follow the contributing guidelines.
  • Code with a bad implementation.
  • Bad Code in general.
  • Complicated operations without comments.
@raklaptudirm raklaptudirm added good first issue help wanted Needs to be worked on in progress Being worked on labels Oct 8, 2021
@raklaptudirm
Copy link
Member Author

raklaptudirm commented Oct 21, 2021

@lvlte @defaude Any of you interested in working on this?

@lvlte
Copy link
Contributor

lvlte commented Oct 21, 2021

Yep sure, I will take a look next week.

@littlefermatlives
Copy link

littlefermatlives commented Oct 22, 2021

Hey, I wanna do it. Please assign it to me.

@raklaptudirm
Copy link
Member Author

raklaptudirm commented Oct 22, 2021

@littlefermatlives Please open a pull request and do the changes. I will review it.

@RenatoLopes771
Copy link
Contributor

RenatoLopes771 commented Oct 27, 2021

If anyone finds some of those and either doesn't want to work on them or don't have to knowledge of the function, feel free to share here so others can do it.

I feel like it would also be a good idea for someone to make a checklist on those files that have been throughly checked for these and don't need any more review.

@benronkth
Copy link

benronkth commented Mar 1, 2022

Hello,
We are working on some improvements to this issue.

/Students from Royal Institute of Technology

@raklaptudirm
Copy link
Member Author

raklaptudirm commented Mar 1, 2022

@benronkth If you have any questions or face any issues, feel free to ask in this thread.

@benronkth
Copy link

benronkth commented Mar 3, 2022

There is a function called rotate (angleInRadians) in two files, namely:

  1. Data-Structures\Vectors\Vector2.js
/**
   * Vector rotation (see https://en.wikipedia.org/wiki/Rotation_matrix)
   *
   * @param angleInRadians The angle in radians by which to rotate the vector.
   * @returns The rotated vector.
   */
  rotate (angleInRadians) {
    const ca = Math.cos(angleInRadians)
    const sa = Math.sin(angleInRadians)
    const x = ca * this.x - sa * this.y
    const y = sa * this.x + ca * this.y
    return new Vector2(x, y)
  }
  1. Recursive\KochSnowflake.js
/**
   * Vector rotation (see https://en.wikipedia.org/wiki/Rotation_matrix)
   *
   * @param angleInDegrees The angle by which to rotate the vector.
   * @returns The rotated vector.
   */
  rotate (angleInDegrees) {
    const radians = angleInDegrees * Math.PI / 180
    const ca = Math.cos(radians)
    const sa = Math.sin(radians)
    const x = ca * this.x - sa * this.y
    const y = sa * this.x + ca * this.y
    return new Vector2(x, y)
  }

As you see they should be doing the same operation but there is a conversion happening in the second file const radians = angleInDegrees * Math.PI / 180. Not having this line results in a test fail in Recursive\test\KochSnowflake.test.js. Which function should be kept (or renamed)?

@raklaptudirm
Copy link
Member Author

raklaptudirm commented Mar 3, 2022

Since the second one is first converting to radians and then essentially running the first function, we can rewrite the second one in terms of the first.

@appgurueu appgurueu added beginner-friendly Easy to implement and removed good first issue labels May 4, 2022
@raklaptudirm raklaptudirm added unassigned feature Adds a new feature code quality Code quality improvement and removed unassigned feature Adds a new feature in progress Being worked on labels May 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beginner-friendly Easy to implement code quality Code quality improvement help wanted Needs to be worked on
Projects
None yet
Development

No branches or pull requests

6 participants