Open privefl opened 7 years ago
@nathan-russell Thoughts?
@privefl Can you remind us which source files of bigmemory you have in mind?
All of them, there are a dispatch function for half of the functions in src/
(e.g. https://github.com/kaneplusplus/bigmemory/blob/master/src/bigmemory.cpp#L2415-L2478).
(That URL lacks a second L before 2478)
Seems fine to me. <shrugs>
But nothing wrong occasional refactoring.
It would certainly tighten the code up. Would you mind showing some example code for how it would look? I originally thought about a macro because there is a lot of repetitive code. However, I went with the current version because a) I thought it was more explicit and b) I didn't have all of the nice Rcpp functionality available now.
In fact, macros are quite easy to use. See an example on my package bigstatsr: https://github.com/privefl/bigstatsr/commit/4ac9b5265970ba140685bea0c8c3d21bc0ec1d27
Oh, OK. For some reason, I thought we were talking about something fancier (and harder to read). Sure, this looks fine to me.
I am just throwing this out here as personal preference which is not a swipe at the nice write-up.
MACROS are still evil. Sometimes we need them (as eg our beloved SEXP
are poor man's OO via unions) but I still think that compiler-driven type safety is preferable. But in the end it all depends on the fine details.
I've just come across the Cleaner Generic Functions with RCPP_RETURN Macros which are implemented there.
I think, with some tweaking, we could use macros for
MatrixAccessor
s and typesraw, char, short, int, float, double, complex
in order to factorize code by using macros instead of extensive dispatch functions.Yet, I don't know anything about C++ macros.
@eddelbuettel @nathan-russell Could this be feasible?