Re: Code Comprehension



Rob Thorpe wrote:
It's a type that works, through coercion. But it does not show the
reader what the code means clearly.

Whenever I deal with characters I always write foo[n] = '\0'; it's
three more character to type sure. But it's also documentation of what
I'm doing with the variable foo, it shows that it's a string/char
operation.

Yeah, I agree that it makes things explicit, and I don't mind typing
the extra 3 characters. But I guess to me it boils down to a judgment
call. Does the context already make it clear enough? If so, then
I might go with a bare 0 just because it is less cluttered. To me,
clutter makes things harder to read, so being explicit about things
has to be balanced against that.

Also, I don't think it's necessarily bad to use type coercion. For
instance, is this code unclear?

float f = 0.0;

The 0.0 is of type double and is coerced to a float, but I don't
have any problem at all reading that and understanding what it would
do, even though this would be more explicit:

float f = 0.0F;

- Logan
.



Relevant Pages

  • Re: converting strings to numbers..
    ... Here, you're first calling a static method valueOf() from the class Float, ... temporary) Float object you call the method floatValue(), ... An object of Character type contains a single character value. ...
    (comp.lang.java.help)
  • Re: [WFB] Help with Rules Interpretation
    ... they should be more explicit in many other points, too, IMO. ... So, if you have a "no-Mark"-unit joined by an Undivided character, does the whole unit benefit from the re-rolls for psychology tests? ... I think so, as one of the special Beast characters, Gorthor, has a special Mark which allows him to re-roll failed psychology and break tests, and there is explicitly written that this also applies to any unit he joins. ...
    (rec.games.miniatures.warhammer)
  • Re: why am I getting this error "varible temp1 might not have been initialized"
    ... What if the person puts in a K for the temperature scale for Kelvin. ... character other than c,C,f, F or puts no character at all and ... So, in the driver, say a person doesn't enter anything for a float ... String strScale1 = keyboard1.next; ...
    (comp.lang.java.help)
  • Re: reading csv files
    ... > character, returning no characters to your program. ... char, long, float, float, float, long ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Fast conversion of a float to character string ( C language )
    ... > I'm looking for a fast way to convert a float into a character ... > string. ... The sprintf() function is too slow for the needs of my ...
    (comp.programming)