Re: how do people feel about exit function from loop
- From: dpb <none@xxxxxxx>
- Date: Mon, 30 Jul 2007 13:27:40 -0500
Robert Morley wrote:
I think it all comes back to the reason we allow more than 2 or 3 characters for a variable name in the first place. For myself, as a general rule, if I have nested loops, I try to make the index names indicate their function. For example:
For lngRow = 1 To 10
For lngCol = 1 To 10
SomeArray(lngRow, lngCol) = SomeArray(lngRow, lngCol) + 1
Next
Next
But, what is gained here other than superfluous verbosity over
For lR = 1 To 10
For lC = 1 To 10
SomeArray(lR, lC) = SomeArray(lR, lC) + 1
Next lC
Next lR
or, even (my choice in this case as I would _always_ declare indices as Long so the "l" is also redundant)
For r = 1 To 10
For c = 1 To 10
SomeArray(r, c) = SomeArray(r, c) + 1
Next r
Next r
?
Using the longer names adds nothing as the row/column will be evident in context and besides the pita of extra typing for no good purpose it raises the odds of statements not fitting on the single line or being longer than can be seen on the display/editor window. And, the excessive "weightiness" of the array subscripts/indices tends to overpower the array/variable names, adding complexity to parsing the line visually as well.
Also note one other pet peeve of mine that I think is a glaring error in VB/BASIC design -- the omitting of the iterator variable name on the closing Next statement. Less of an issue the shorter the loop is, but should _never_ be omitted imo simply for clarity of intent.
That said, in something not nested, I'll often use a simpler name (unless I'm already using a logical name in other loops), even though when you think about it, the context is nearly the same. For example:
For i = 1 To 10
SomeArray(1, i) = SomeArray(1, i) + 1
Next
But at the risk of inciting another debate over what constitutes style, I believe this is a style choice for each user to decide on their own.
Certainly it is a style choice but I think there are reasons for selecting certain styles that far transcend the apparent minimal benefit...
I'll close by noting the parallel to mathematical notation of "x sub i" should not be disregarded with impunity. Being, of course, an engineer as opposed to a software professional and heavily involved in modeling and such as the primary applications, I am far more influenced in that regards than many VB users. Still, the precedent is there and should be recognized as having a long and distinguished lineage.
Again, imo, $0.02, etc., ...
--
.
- Follow-Ups:
- Re: how do people feel about exit function from loop
- From: Robert Morley
- Re: how do people feel about exit function from loop
- From: Ken Halter
- Re: how do people feel about exit function from loop
- From: David Kerber
- Re: how do people feel about exit function from loop
- From: Ken Halter
- Re: how do people feel about exit function from loop
- References:
- how do people feel about exit function from loop
- From: greg
- Re: how do people feel about exit function from loop
- From: Ken Halter
- Re: how do people feel about exit function from loop
- From: Jan Hyde (VB MVP)
- Re: how do people feel about exit function from loop
- From: Steve Gerrard
- Re: how do people feel about exit function from loop
- From: Michael C
- Re: how do people feel about exit function from loop
- From: Robert Morley
- Re: how do people feel about exit function from loop
- From: Michael C
- Re: how do people feel about exit function from loop
- From: Robert Morley
- Re: how do people feel about exit function from loop
- From: Michael C
- Re: how do people feel about exit function from loop
- From: Robert Morley
- Re: how do people feel about exit function from loop
- From: Michael C
- Re: how do people feel about exit function from loop
- From: Robert Morley
- Re: how do people feel about exit function from loop
- From: Michael C
- Re: how do people feel about exit function from loop
- From: Robert Morley
- Re: how do people feel about exit function from loop
- From: dNagel
- Re: how do people feel about exit function from loop
- From: Robert Morley
- Re: how do people feel about exit function from loop
- From: dNagel
- Re: how do people feel about exit function from loop
- From: dNagel
- Re: how do people feel about exit function from loop
- From: Steve Gerrard
- Re: how do people feel about exit function from loop
- From: Larry Serflaten
- Re: how do people feel about exit function from loop
- From: Ralph
- Re: how do people feel about exit function from loop
- From: dpb
- Re: how do people feel about exit function from loop
- From: Robert Morley
- how do people feel about exit function from loop
- Prev by Date: OT: Re: Wii bit of help please???
- Next by Date: Re: how do people feel about exit function from loop
- Previous by thread: Re: how do people feel about exit function from loop
- Next by thread: Re: how do people feel about exit function from loop
- Index(es):
Relevant Pages
|