Opened 5 years ago

Last modified 4 years ago

#5905 new enhancement

Clean up large copy pasted code parts in OMEdit

Reported by: Anatoly Trosinenko Owned by: Adeel Asghar
Priority: low Milestone: Future
Component: OMEdit Version:
Keywords: copy-paste, pmd, cpd Cc:

Description

While adding a Call Function context menu entry back in 2018, I have spotted large amounts of copy-pasted code inside the OMEdit C++ codebase. While copy-pasted code does not introduce any bugs on its own, such refactoring could improve code maintainability a bit. Unfortunately, I have not managed to investigate it better since then. Creating a separate issue, because the original pull request was closed long ago.

For example, at the time of writing, both HTMLEditor.cpp and OMSimulatorEditor.cpp files have 50-line highlightMultiLine functions. Such cases can be found by using Copy-Paste Detector component from PMD. Meanwhile, it has Modelica support since 6.21.0 version.

You could see the original discussion for more details, as well.

Change History (2)

comment:1 by Francesco Casella, 5 years ago

@atrosinenko, thanks for the analysis!

According to your understanding, how much manual work is needed to do the refactoring, if proper tools are employed?

comment:2 by Anatoly Trosinenko, 4 years ago

Unfortunately, I don't have strong understanding on performing this effectively and review-friendly.

Searching for copy-pasted snippets should be quite straightforward. Basically it just requires downloading PMD binary distribution and running a single command with proper parameters.

Fixing, on the other hand, probably involves much more manual work and some testing afterwards. For the particular case of two almost identical 50-line snippets, I have no ideas better than copying both snippets to some diff tool such as Meld, enumerating all difference and manually factoring them out (after all, these are O(1) large code snippets, so it is more about general design).

For lots of small snippets, there may help some tools for semantic patching such as coccinelle, but I never used them myself and I'm not sure this particular one can process C++. Using such tool may allow more focus on reviewing a trivial semantic patch and just glancing on huge diff (provided it is reproducible with such patch).

Note: See TracTickets for help on using tickets.