Re: help with statistics library



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.
.



Relevant Pages

  • Re: Correct way to handle "makes integer from pointer without cast
    ... it's also sometimes necessary to cast the types of the arguments to ... make sure they fit exactly what's stated in the format string. ...
    (comp.unix.programmer)
  • Re: S02E04 - Best episode yet...
    ... Simon Brooke writes: ... <snip stuff that I agree with but don't have anything to add> ... cast - you could easily believe in her as someone sexy because ... but turned it down in favour of acting. ...
    (uk.media.tv.sf.drwho)
  • Re: pointers chainging in a function call?
    ... snip ... ... He should cast the pointer arguments to printf to ...
    (comp.lang.c)
  • Re: Bulimia?
    ... I like to cast a few stones in your direction when you've been quiet for a while just to make sure you are ok :-) I presume by your relaxed answer you are? ...
    (uk.local.kent)
  • Re: Bulimia?
    ... I like to cast a few stones in your direction when you've been quiet for a while just to make sure you are ok :-) I presume by your relaxed answer you are? ...
    (uk.local.kent)