Re: help with statistics library



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.
E.g. if you divide a double by an int you don't have to cast the int
to double, the compiler will do that for you. The same holds for
instances where you assign an int to a double. Of course, the cast
doesn't hurt, but as a rule I avoid casts unless they are really
necessary and thus see casts as a "red flag" that says "here's
something happening that may need re-examination".

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); 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. On the other hand:

y = x/(double)n;

makes it immediately clear that a cast is intended.

No big deal though, it's probably a personal preference.

--
Lionel B
.



Relevant Pages

  • Re: Reading a large number of text files into an array
    ... > convert this string into an array of doubles? ... > int main ... the array dependent on the maximum length of all components from which the ... No need for either of the casts here. ...
    (comp.lang.c)
  • Re: out
    ... The above code before I added the int casts just by a gut feeling didn't ... By adding the int casts in front of the NULLs what have I really done? ... The casts are likely to silence some error messages, ... electrical tape over the warning lights on the dashboard; ...
    (comp.lang.c)
  • Re: Problems With strtof()
    ... > int main ... i.e. invoking gcc with the additional ... While the casts here don't ... Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org ...
    (comp.lang.c)
  • Re: my handy-dandy, "coding style" script
    ... Warning about this practice only leads the defensive programmer ... to clutter programs with dozens of casts to void. ... int var = 13; ...
    (Linux-Kernel)
  • Re: Pass value of short type
    ... unsigned short into an unsigned int, ... be no warning, because the data will always fit. ... the implicit conversion is a promotion from unsigned short ... I agree you should avoid casts whenever possible (and especially avoid ...
    (comp.lang.cpp)