MetaBrainz Foundation

Find duplicate code in BookBrainz and refactor to remove it

When writing new code, developers often find that they want to use a snippet of code that they've already written. When this happens, the developer has two choices - they can either copy and paste the old snippet and modify it to make it work as they wish, or they can abstract the snippet into a function, and use that same function in two (or more) places.

The second approach is the best - it reduces the amount of code that needs to be maintained and sticks to the "don't repeat yourself" principle. However, the first approach is often used, because developers don't always consider the long term impact of their decisions.

We'd like you to look through the bookbrainz-site repository and identify similar or duplicate code. You might be able to detect these duplicates automatically, using tools such as jsinspect or jscpd.

Once you've found an instance of duplicate code, think about how a single function can be created to contain the duplicate code. You'll want to identify the differences, and work out how they can be passed as parameters to the function. When you've designed your solution, write the new function, and replace the old duplicated code with function calls.

To submit your work, clone the bookbrainz-site repository and create a new branch named "duplicate-refactor-YOUR_GCI_USERNAME". Commit your changes, using small commits which make clear, self-contained changes, and using the conventions here. Finally, push your work to GitHub and create a new Pull Request.

Task tags

  • bookbrainz
  • javascript
  • refactor

Students who completed this task

Eshan Singh, Robin Richtsfeld

Task type

  • code Code
  • done_all Quality Assurance
close

2017