Re: Correct C++ tutorial part 3 "Intro to loops" available (Windows, mingw/msvc/std)
From: Attila Feher (attila.feher_at_lmf.ericsson.se)
Date: 01/27/05
- Next message: Attila Feher: "Re: Dating"
- Previous message: Ivan Vecerina: "Re: Array object operator overloading"
- In reply to: Alf P. Steinbach: "Re: Correct C++ tutorial part 3 "Intro to loops" available (Windows, mingw/msvc/std)"
- Next in thread: Alf P. Steinbach: "Re: Correct C++ tutorial part 3 "Intro to loops" available (Windows, mingw/msvc/std)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 27 Jan 2005 15:28:45 +0200
Alf P. Steinbach wrote:
[SNIP]
>>> * If you use integer update you should use integer type for the
>>> variable.
>>
>> Why? You have introduced your lines with the word reasoning, but I
>> see no reason told for this statement.
>
> It seems to boil down to two issues: why it's not a good idea to use a
> misleading type (maintainability), and whether a floating point type
> can always represent all values of an integral type exactly
> (technical).
Why would a floating point type misleading if I need a floating point value?
Furthermore - on the same note - why would I care about it representing or
not integer values, if I needed a floating point one in the first place?
[SNIP]
> Yes, to the latter two sentences. I wonder whether you are happy with
> the resolution of that issue as it turned out in the rest of the
> thread? That is, adding the parenthetical expression "unless you
> really know what you're doing"?
That is one way to put it. :-) But I guess there is another and probably
more important reason/cause: do you need a floating point iteration or not?
:-) And then comes the know what you do, do what you know. ;-)
[SNIP]
> Iterators and pointers as loop control variables is a good point,
> thanks.
No problemo. :-)
> The discussion above was trapped in the implicit context of numeric
> loop control variables.
And it possibly should for that very-beginner part, but IMHO the rule itself
may need to be worded differently. So that it suggests to the reader that
the rules is supposed to say: do not use floating point unless you really
need it (IMHO this goes not only for loops), so basically tell what is
wrong, instead of identifying what is right. Because limiting the possible
types (in this case/stage) will rule out valid cases, valid cases you did
not introduce yet for a reason.
> Possibly I should add the word "numeric" in the advice. But I think
> it would then hang in thin air, not related to the rest of the
> discussion. Suggestions?
What I wrote above could probably be worded.
Loops can do (at least) counting and iterating, not taking into account the
"abuses" of them, like when a do {} while(0); loop (with breaks inside) is
used instead of a local try-catch...
So the loop variable in those non-abuse cases can mean a numeric value
(counting), and index value (addressing into containers using the array
access) or an iterator. A loop walking a linked list (with the loop
variable being a pointer to one list element) is (IMHO) a special case of
iteration.
My point is: there can be numerous other (legal and "good design") uses of
loops, which the current rule rules out. If the rule could be worded to
only say what not to do, the "unknown number of other legal uses" would not
be affected by it.
-- Attila aka WW
- Next message: Attila Feher: "Re: Dating"
- Previous message: Ivan Vecerina: "Re: Array object operator overloading"
- In reply to: Alf P. Steinbach: "Re: Correct C++ tutorial part 3 "Intro to loops" available (Windows, mingw/msvc/std)"
- Next in thread: Alf P. Steinbach: "Re: Correct C++ tutorial part 3 "Intro to loops" available (Windows, mingw/msvc/std)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|