[Rd] Why no .Machine$sizeof.double?

Earl F. Glynn efg at stowers-institute.org
Tue Oct 18 22:08:59 CEST 2005


"Thomas Lumley" <tlumley at u.washington.edu> wrote in message
news:Pine.LNX.4.63a.0510181039440.30016 at homer24.u.washington.edu...
> On Tue, 18 Oct 2005, Earl F. Glynn wrote:
>
> > Whis is there a .Machine$sizeof.longdouble but no
.Machine$sizeof.double?
> >
>
> sizeof(double) is always 8 and sizeof(int) is always 4, because R requires
> the IEEE/IEC standard arithmetic types.  R will not compile with any other
> sizes.

But it's a common, recommended software engineering practice to define
mnemonic, named constants.

If I were to see code like .Machine$sizeof.double * N.COL * N.ROW, I know
that's the number of bytes in a matrix of doubles. If I see code that is 8 *
N.COL * N.ROW, I can guess what "8" means, but I could guess wrong.  I wrote
code that looks just like this today because I couldn't find the defined
constant.  Will someone else reading my code automatically know what the "8"
means?

The use of  literal constants should be discouraged.  I encourage more to
study Section 12.7 "Named Constants" in the book "Code Complete 2" (see
http://www.cc2e.com/).  At some point the R community should become more
receptive to named constant to make R code more readable and easier to
maintain.  But for now, I guess I still have a minority opinion on this
matter in the R community.

efg



More information about the R-devel mailing list