Code duplication - best practices

asked 2018-10-13 10:44:21 -0600

mathijs gravatar image

updated 2018-10-13 15:31:55 -0600

I was wondering what the best practices is for duplication of code between nodes.

For example:

I grouped together two packages with a metapackage called perception, namely; object detection and localization.

object detection package has a node -> ballDetection

localization package has a node -> linesDetection

As you can already assume, there is a lot of code duplication in these nodes. For example, if I want to display images in both nodes to the screen, I have the exact same code in both nodes.

Should I create a library that both nodes can use to display images to the screen? Or should I use nodes for everything? What is the best practice for situations like this?

edit retag flag offensive close merge delete

Comments

Not an answer, but:

I have a metapackage for perception. In this metapackage two packages can be found;

this is a little strange: metapackages don't contain anything, especially not other packages.

If yours does, then it's not a metapackage.

gvdhoorn gravatar imagegvdhoorn ( 2018-10-13 12:36:45 -0600 )edit

You are right. I edited my question.

mathijs gravatar imagemathijs ( 2018-10-13 13:27:30 -0600 )edit

I have a package for perception. In this package two packages can be found

do you really have nested packages?

gvdhoorn gravatar imagegvdhoorn ( 2018-10-13 14:42:39 -0600 )edit

I am confused. Maybe I did mean metapackage:

http://wiki.ros.org/ROS/Concepts

Meta package is meant to group together packages. That's what I did. I edited my post, it is correct now.

mathijs gravatar imagemathijs ( 2018-10-13 15:30:56 -0600 )edit

Please check REP-140: metapackage: metapackages are not pkgs that contain other pkgs. They only refer to them (in their package.xml).

See #q256493 for an explanation of the concept and its utility.

gvdhoorn gravatar imagegvdhoorn ( 2018-10-13 15:33:36 -0600 )edit

For actions such as displaying an image on the screen, then I would put them in a library if you want to share that code. Nodes are generally used to encompass atomic building blocks of a robotic system.

PeteBlackerThe3rd gravatar imagePeteBlackerThe3rd ( 2018-10-13 16:01:59 -0600 )edit

Agree with PeteBlackerThe3rd, you can use libraries to keep the common functionality. Depending on project complexity you can use git submodules for your libraries and assuming each package is a standalone repo you could have a nice reusability and version control for the common library code.

msadowski gravatar imagemsadowski ( 2018-10-15 11:36:54 -0600 )edit