[Rcpp-devel] shallow/deep copy

Zhongyi Yuan zhongyi-yuan at uiowa.edu
Thu Sep 1 03:52:36 CEST 2011


Hi Darren,

Thank you so much for taking time to write the illustrative example. That
makes perfect sense.

I had the feeling that being explicit might be a better choice when projects
get bigger. So far my codes are mainly for numerical studies in my research
and are generally short, but I do want to keep a good style of coding as I
expect myself to code more in future.

Thanks, Darren.

Zhongyi

On Wed, Aug 31, 2011 at 7:09 PM, Darren Cook <darren at dcook.org> wrote:

> > Can I ask for specific reasons why people prefer explicit?  Any potential
> > danger for not being explicit?
>
> Hello Zhongyi,
> It is hard to show in a toy example; in fact "using namespace" is best
> for code examples where you want to get an idea across and not cloud it
> with too much other code.
>
> But see the below example, and imagine the "//..." bits are dozens of
> lines. When you see f(x) you don't know which function will be called.
> You have to stop and search up to find the currently active namespace
> definition.
> The bigger your project, and the more 3rd party libraries you deal with,
> the more this slows you down.
>
> See also:
>  http://www.parashift.com/c++-faq-lite/coding-standards.html#faq-27.5
>
> Darren
>
>
> //------------------------------------------
>
> #include <iostream>
>
> namespace xx{
>  double f(double x){
>  return x*x;
>  }
> }
>
>
> namespace yy{
>  double f(double y){
>  return y+y;
>  }
> }
>
>
> void one(double x){
> using namespace xx;
> //....
> std::cout<<f(x)<<"\n";
> }
>
>
> void two(double x){
> using namespace yy;
> //....
> std::cout<<f(x)<<"\n";
> }
>
>
>
> int main (int,char**){
> const double PI=3.14;
> one(PI);
> two(PI);
> std::cout<<xx::f(PI)<<"\n";
> std::cout<<yy::f(PI)<<"\n";
> return 0;
> }
>
>
> --
> Darren Cook, Software Researcher/Developer
>
> http://dcook.org/work/ (About me and my work)
> http://dcook.org/blogs.html (My blogs and articles)
> _______________________________________________
> Rcpp-devel mailing list
> Rcpp-devel at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20110831/f0826389/attachment.htm>


More information about the Rcpp-devel mailing list