Re: help with statistics library
- From: Richard Heathfield <rjh@xxxxxxxxxxxxxxx>
- Date: Thu, 26 Apr 2007 10:19:51 +0000
Lionel B said:
On Thu, 26 Apr 2007 00:34:23 +0000, Jens Thoms Toerring wrote:
Richard Weeks <rweeks@xxxxxxxxxx> wrote:
http://members.shaw.ca/bystander/statsource.html
My first impression after a short look is that it looks rather
well-written and I so simply start with nit-picking:
[...]
4) There are a few instances where you cast where it isn't necessary.
<snip>
Just a nitpick of your nitpick: I tend to take the opposite view that
explicit casts are preferable to implicit casts, since they make the
intention of the code clearer (at the expense of some verbosity);
Just a nitpick of your nitpick of his nitpick: a cast is an explicit
conversion, so "implicit cast" is a contradiction in terms.
if I see:
double x,y;
int n;
/* lots of code */
y = x/n;
then I have to remind myself (with reference to the declaration of n)
that casting is taking place.
But it isn't! A conversion is taking place, sure, but there is no cast
here. Furthermore, there is no need to worry about it, since the
correct result will be obtained anyway. The only conceivable issue is
if the type of x were to change (to an integer type) without a
corresponding change in y. If (and, I believe, *only* if) that were a
possibility, then, from a defensive programming perspective, either you
should cast or (and, in my view, preferably) you could split the
division like this:
y = x;
y /= n;
in which case the division will be done using floating-point arithmetic.
I accept that my preference for this way of avoiding the cast might be
considered - um - eccentric. :-)
<snip>
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
.
- Follow-Ups:
- Re: help with statistics library
- From: Lionel B
- Re: help with statistics library
- References:
- help with statistics library
- From: Richard Weeks
- Re: help with statistics library
- From: Ico
- Re: help with statistics library
- From: Richard Weeks
- Re: help with statistics library
- From: Willem
- Re: help with statistics library
- From: Richard Weeks
- Re: help with statistics library
- From: Jens Thoms Toerring
- Re: help with statistics library
- From: Lionel B
- help with statistics library
- Prev by Date: Re: [C++] Command line parser
- Next by Date: Re: help with statistics library
- Previous by thread: Re: help with statistics library
- Next by thread: Re: help with statistics library
- Index(es):
Relevant Pages
|