Having identical source, or near identical source does not make it identical code.
Sure right now these two sections operate similarly, they have similar definitions, and some cut/paste checkers report them as copies. This is just a code smell.
- Should I do something about it? Probably.
- What should I do about it? Ask questions.
Ask Questions Like:
- Do these two pieces of code serve the same purpose?
- Do these pieces of code live on the same shearing level (do they change at the same time)?
- Is there a reason why the piece of code in one system will change, and not the other piece of code?
- Does the source code repository show evidence of similar changes?
- Is there a speed/resource limit that one piece of code is operating in that the other is not? (ie mobile vs. mainframe)
- Are the tests near identical?
If the answers are mostly they are similar then, yes probably (near-)identical code.
- Are there other instances of this duplication?
- Is this code stable, and likely to remain so?
- How malleable is the code currently?
- Is it sensible to add another dependency to each project?
- Who is responsible for maintaining this new library?
- Who is being subjugated to the whims of an external maintainer?
- Would deduplicating this code make any project less readable?
- Would deduplicating this code make any project less changeable?
There are other question you might ask based on the context, but these are good for starting the conversation.
The conversation is the important part here. Developing software is a team sport, in a game that only ends when the software is abandoned. The important part is working with that team to make the code better. Even if you are a sole-developer, your team also includes anyone who writes a plugin for your system, any of the systems users, the system admins, etc...
It may not make sense to discuss code deduplication with a system user, but their needs shape what the system needs to be, and reveal the forces acting on this "duplicate" code. With that knowledge you can see the ramifications of deduplication.
- If you deduplicate this code, only for another team-member to split it out again because a change has to happen here, but no where else. You have made created an obstacle which has made work out of thin air.
- On the otherhand, if by deduplicating this code allows that other team member to fix a bug in that area easily. You have removed obstacles to that work.