Re: help with statistics library
- From: Lionel B <me@xxxxxxxxxxx>
- Date: Thu, 26 Apr 2007 11:13:23 +0000 (UTC)
On Thu, 26 Apr 2007 10:19:51 +0000, Richard Heathfield wrote:
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.
Doh! For "cast" read "conversion"
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.
Ditto.
Furthermore, there is no need to worry about it, since the correct
result will be obtained anyway.
I don't think I even implied that omitting a cast would result in
incorrect code; simply that casts can make the intention of the code
somewhat more transparent to someone (me!) reading it.
Basically, if I *don't* see a cast where an implicit conversion is going
to happen, there's always in the back of my mind: "Did the programmer
realise that there's a conversion here? Is this what they intended? Did
they think about it?", whereas if I see a cast then I *know* the
programmer has thought about it.
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,
I hadn't even got round to mentioning the potential for error-proneness
of implicit conversions, but now that you bring it up...
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. :-)
I'll accept that too ;-)
--
Lionel B
.
- Follow-Ups:
- Re: help with statistics library
- From: Richard Heathfield
- 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
- Re: help with statistics library
- From: Richard Heathfield
- help with statistics library
- Prev by Date: Re: help with statistics library
- Next by Date: CfP: 7th Domain-Specific Modeling workshop at OOPSLA
- Previous by thread: Re: help with statistics library
- Next by thread: Re: help with statistics library
- Index(es):
Relevant Pages
|