0

I have a working R package including the necessary R/Cpp working. My question here is more of a 'good practices' when using nested namespace.

Currently, my package has; 1) cost functions, 2) optimization functions, 3) parallel workers that call the optimization functions. At present the workers are defined in the .cpp files that contain the exported (to R) cpp function. The optimization functions have one namespace and header file and the cost functions have they're own header/namespace file. All the optimization functions call a cost function so they include the 'cost function' header and use the 'cost function' namespace.

As the .cpp files that run in parallel and call the workers are on the order of ~700 lines, I was thinking to move the workers to a separate namespace and header file. These include the 'optimization' header and use the 'optimization' namespace.

That got me thinking, do I really need 3 nested namespaces? It would be nice not to have 3 namespaces with 2-4 functions in each of them. Additionally, the functions are/would always be called in order parallel_worker/optimize_function/cost_function, each living in a different namespace/header.

skatz
  • 115
  • 7
  • 1
    I don't see an Rcpp question here (in the sense of "what questions can get answered on SO"). You may have a question for the _Code Review_ stack exchange site, or some more general program design question. Can you make it more specific, or maybe consider moving it somewhere where it may find a more suitable audience? – Dirk Eddelbuettel Jan 16 '19 at 14:28
  • Ok, I will be a bit more specific with. Within the context of an R package with Rcpp, would you nest three namespaces where namespace-A, calls a function in namespace-B which calls a function in namespace-C? Or, could all the functions/workers be housed in the same namespace? If so is there a preference or an established 'convention' from someone who has experience, writing such R/Rcpp packages. – skatz Jan 16 '19 at 22:29
  • 1
    The question is why you introduce different namespaces/headers in the first place. If you are aiming for modularization, then a common goal is low coupling between modules and high cohesion within modules. Currently you are in the opposite situation. See http://www.codingthearchitecture.com/2015/03/08/package_by_component_and_architecturally_aligned_testing.html for a similar discussion in the Java world. – Ralf Stubner Jan 17 '19 at 11:27

0 Answers0