https://bugs.documentfoundation.org/show_bug.cgi?id=155630

            Bug ID: 155630
           Summary: Deduplicate copy/paste code
           Product: LibreOffice
           Version: 7.6.0.0 alpha1+ Master
          Hardware: All
                OS: All
            Status: UNCONFIRMED
          Severity: normal
          Priority: medium
         Component: LibreOffice
          Assignee: libreoffice-bugs@lists.freedesktop.org
          Reporter: hoss...@libreoffice.org

Description.
Copy pasting the code to do (almost) similar things in different places of the
code base is usually considered a bad practice. There are many constructs in
C/C++/Java and other programming languages that let the programmer to avoid
duplicate code.
This is the task to find duplicate code in LibreOffice, and de-duplicate them
by introducing new functions that do the shared things, and other similar
tricks.

Finding duplicate code
Finding parts of the code that are similar to other parts is not an easy task
if you do it manually. But, using appropriate tool it can be much easier. One
of such tools that can find duplicate code is PMD:

PMD Source Code Analyzer:
https://pmd.github.io/
https://github.com/pmd/pmd

You can use this tool to find the duplicate code, and then try changing it to
remove the duplicate parts.

Changing the code
One of the ways to de-duplicate the code is to move the shared part of the code
to a new function, and then call it in place of the duplicated code.

Examples
This is a reboot of the previous task tdf#39593, so you can refer to the
example commits from the above issue. As an example, you can see this commit
among them:

tdf#39593 vcl/win/gdi: extract brush updating into method
https://git.libreoffice.org/core/+/7311a88baa8c30eeb61d897f43ac3f5b481ed01f%5E%21

Note: You have to make sure that the new code has the same functionality as the
old one, and it does not cause bad impact on performance.

-- 
You are receiving this mail because:
You are the assignee for the bug.

Reply via email to