Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #6781 > unrolled thread
| Started by | Roedy Green <see_website@mindprod.com.invalid> |
|---|---|
| First post | 2011-08-03 15:40 -0700 |
| Last post | 2011-08-10 09:05 -0700 |
| Articles | 17 — 12 participants |
Back to article view | Back to comp.lang.java.programmer
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: looping through a list, starting at 1 Roedy Green <see_website@mindprod.com.invalid> - 2011-08-03 15:40 -0700
Re: looping through a list, starting at 1 Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2011-08-03 20:53 -0300
Re: looping through a list, starting at 1 Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-08-03 21:10 -0400
Re: looping through a list, starting at 1 Gene Wirchenko <genew@ocis.net> - 2011-08-03 21:22 -0700
Re: looping through a list, starting at 1 "John B. Matthews" <nospam@nospam.invalid> - 2011-08-03 23:36 -0400
Re: looping through a list, starting at 1 RedGrittyBrick <RedGrittyBrick@spamweary.invalid> - 2011-08-04 09:37 +0100
Re: looping through a list, starting at 1 Chris Riesbeck <Chris.Riesbeck@gmail.com> - 2011-08-04 12:47 -0500
Re: looping through a list, starting at 1 markspace <-@.> - 2011-08-04 11:27 -0700
Re: looping through a list, starting at 1 Patricia Shanahan <pats@acm.org> - 2011-08-04 13:58 -0700
Re: looping through a list, starting at 1 markspace <-@.> - 2011-08-04 14:36 -0700
Re: looping through a list, starting at 1 Patricia Shanahan <pats@acm.org> - 2011-08-04 14:46 -0700
Re: looping through a list, starting at 1 RedGrittyBrick <RedGrittyBrick@spamweary.invalid> - 2011-08-05 10:09 +0100
Re: looping through a list, starting at 1 Gene Wirchenko <genew@ocis.net> - 2011-08-05 14:46 -0700
Re: looping through a list, starting at 1 Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-08-04 20:51 -0400
Re: looping through a list, starting at 1 Tim Slattery <Slattery_T@bls.gov> - 2011-08-05 08:38 -0400
Re: looping through a list, starting at 1 Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-08-05 10:22 +0000
Re: looping through a list, starting at 1 Lew <lewbloch@gmail.com> - 2011-08-10 09:05 -0700
| From | Roedy Green <see_website@mindprod.com.invalid> |
|---|---|
| Date | 2011-08-03 15:40 -0700 |
| Subject | Re: looping through a list, starting at 1 |
| Message-ID | <8djj37pg6o35jb1b8lskefb4jmb2iadmbe@4ax.com> |
On 1 Aug 2011 22:45:41 GMT, ram@zedat.fu-berlin.de (Stefan Ram) wrote,
quoted or indirectly quoted someone who said :
>for( int i = 1; i < l.size(); ++i ){ final E e = l.get( 0 ); ... }
This one is clearer. The problem is most people will just glance at it
and read it as for( int i=0; i<l.zise(); i++ )
I think you mean i++ not ++i.
you might use for ( E e : l )
Then use logic to avoid the first elt, though that is overkill for
ensuring noone misreads your code.
--
Roedy Green Canadian Mind Products
http://mindprod.com
Most of computer code is for telling the computer
what do if some very particular thing goes wrong.
[toc] | [next] | [standalone]
| From | Arved Sandstrom <asandstrom3minus1@eastlink.ca> |
|---|---|
| Date | 2011-08-03 20:53 -0300 |
| Message-ID | <7cl_p.425844$lW4.338969@newsfe07.iad> |
| In reply to | #6781 |
On 11-08-03 07:40 PM, Roedy Green wrote:
> On 1 Aug 2011 22:45:41 GMT, ram@zedat.fu-berlin.de (Stefan Ram) wrote,
> quoted or indirectly quoted someone who said :
>
>> for( int i = 1; i < l.size(); ++i ){ final E e = l.get( 0 ); ... }
>
> This one is clearer. The problem is most people will just glance at it
> and read it as for( int i=0; i<l.zise(); i++ )
Errr, I don't know if "most" people would misread the above, although no
doubt some would, but how can you assert that something is more clear
then immediately assert that most people will mis-read it?
> I think you mean i++ not ++i.
In this particular case why would it matter? Write a simple test case
that has 2 loops, one using pre-increment for the increment expression,
one using post-increment, and see if there's a difference. There won't
be: the increment expression is invoked *after* each iteration through
the loop.
> you might use for ( E e : l )
> Then use logic to avoid the first elt, though that is overkill for
> ensuring noone misreads your code.
AHS
[toc] | [prev] | [next] | [standalone]
| From | Eric Sosman <esosman@ieee-dot-org.invalid> |
|---|---|
| Date | 2011-08-03 21:10 -0400 |
| Message-ID | <j1crjn$smg$1@dont-email.me> |
| In reply to | #6781 |
On 8/3/2011 6:40 PM, Roedy Green wrote:
> On 1 Aug 2011 22:45:41 GMT, ram@zedat.fu-berlin.de (Stefan Ram) wrote,
> quoted or indirectly quoted someone who said :
>
>> for( int i = 1; i< l.size(); ++i ){ final E e = l.get( 0 ); ... }
>
> This one is clearer. The problem is most people will just glance at it
> and read it as for( int i=0; i<l.zise(); i++ )
Soundz! Can beingz unable to diztinguizh onez from seroez exizt
outzide of sooz?
> I think you mean i++ not ++i.
Say what? Or, rather, say why?
--
Eric Sosman
esosman@ieee-dot-org.invalid
[toc] | [prev] | [next] | [standalone]
| From | Gene Wirchenko <genew@ocis.net> |
|---|---|
| Date | 2011-08-03 21:22 -0700 |
| Message-ID | <0i7k37trtsprjh1jlkegf46cccg7moag09@4ax.com> |
| In reply to | #6783 |
On Wed, 03 Aug 2011 21:10:46 -0400, Eric Sosman
<esosman@ieee-dot-org.invalid> wrote:
>On 8/3/2011 6:40 PM, Roedy Green wrote:
>> On 1 Aug 2011 22:45:41 GMT, ram@zedat.fu-berlin.de (Stefan Ram) wrote,
>> quoted or indirectly quoted someone who said :
>>
>>> for( int i = 1; i< l.size(); ++i ){ final E e = l.get( 0 ); ... }
>>
>> This one is clearer. The problem is most people will just glance at it
>> and read it as for( int i=0; i<l.zise(); i++ )
>
> Soundz! Can beingz unable to diztinguizh onez from seroez exizt
>outzide of sooz?
Mr. Zozman, pleaze do not make fun of Roedy.
>> I think you mean i++ not ++i.
>
> Say what? Or, rather, say why?
Add me to the list of those asking why.
Sincerely,
Gene Wirchenko
[toc] | [prev] | [next] | [standalone]
| From | "John B. Matthews" <nospam@nospam.invalid> |
|---|---|
| Date | 2011-08-03 23:36 -0400 |
| Message-ID | <nospam-9625F7.23364303082011@news.aioe.org> |
| In reply to | #6781 |
In article <8djj37pg6o35jb1b8lskefb4jmb2iadmbe@4ax.com>, Roedy Green <see_website@mindprod.com.invalid> wrote: > I think you mean i++ not ++i. IIUC, the result of evaluating any ForUpdate expression is discarded, so I'm not sure how the difference would matter. <http://java.sun.com/docs/books/jls/third_edition/html/statements.html#14.14.1.2> -- John B. Matthews trashgod at gmail dot com <http://sites.google.com/site/drjohnbmatthews>
[toc] | [prev] | [next] | [standalone]
| From | RedGrittyBrick <RedGrittyBrick@spamweary.invalid> |
|---|---|
| Date | 2011-08-04 09:37 +0100 |
| Message-ID | <4e3a5a4c$0$2527$da0feed9@news.zen.co.uk> |
| In reply to | #6786 |
On 04/08/2011 04:36, John B. Matthews wrote: > In article<8djj37pg6o35jb1b8lskefb4jmb2iadmbe@4ax.com>, > Roedy Green<see_website@mindprod.com.invalid> wrote: > >> I think you mean i++ not ++i. > > > IIUC, the result of evaluating any ForUpdate expression is discarded, > so I'm not sure how the difference would matter. Since I see postincrement a lot more than I see preincrement and since i++ is idiomatic in that construct, when seeing ++i I tend to stop and wonder whether the writer intended something else. So I suppose it might matter if engendering a sense of distrust or unease in maintenance programmers matters. -- RGB
[toc] | [prev] | [next] | [standalone]
| From | Chris Riesbeck <Chris.Riesbeck@gmail.com> |
|---|---|
| Date | 2011-08-04 12:47 -0500 |
| Message-ID | <9a04aaFp76U1@mid.individual.net> |
| In reply to | #6790 |
On 8/4/2011 3:37 AM, RedGrittyBrick wrote: > On 04/08/2011 04:36, John B. Matthews wrote: >> In article<8djj37pg6o35jb1b8lskefb4jmb2iadmbe@4ax.com>, >> Roedy Green<see_website@mindprod.com.invalid> wrote: >> >>> I think you mean i++ not ++i. >> >> >> IIUC, the result of evaluating any ForUpdate expression is discarded, >> so I'm not sure how the difference would matter. > > Since I see postincrement a lot more than I see preincrement and since > i++ is idiomatic in that construct, when seeing ++i I tend to stop and > wonder whether the writer intended something else. So I suppose it might > matter if engendering a sense of distrust or unease in maintenance > programmers matters. > Makes no difference in this context for C and Java. In C++, an overloaded postfix ++ for a user data structure typically has to create and return a temporary, so modern C++ guides often recommend getting into the ++i habit, and using i++ only when you really need it. But no recommendation to rename the language to ++C yet.
[toc] | [prev] | [next] | [standalone]
| From | markspace <-@.> |
|---|---|
| Date | 2011-08-04 11:27 -0700 |
| Message-ID | <j1eoba$uj6$1@dont-email.me> |
| In reply to | #6793 |
On 8/4/2011 10:47 AM, Chris Riesbeck wrote: > In C++, an > overloaded postfix ++ > See? This is why I'm against any kind of operator overloading in Java. Too much stupid out there.
[toc] | [prev] | [next] | [standalone]
| From | Patricia Shanahan <pats@acm.org> |
|---|---|
| Date | 2011-08-04 13:58 -0700 |
| Message-ID | <Q7Odnef35YdGmqbTnZ2dnUVZ_qWdnZ2d@earthlink.com> |
| In reply to | #6795 |
On 8/4/2011 11:27 AM, markspace wrote: > On 8/4/2011 10:47 AM, Chris Riesbeck wrote: >> In C++, an >> overloaded postfix ++ >> > > > See? This is why I'm against any kind of operator overloading in Java. > Too much stupid out there. > > So what operator should have been used for String concatenation, instead of overloading "+"? Patricia
[toc] | [prev] | [next] | [standalone]
| From | markspace <-@.> |
|---|---|
| Date | 2011-08-04 14:36 -0700 |
| Message-ID | <j1f3ds$d7i$1@dont-email.me> |
| In reply to | #6796 |
On 8/4/2011 1:58 PM, Patricia Shanahan wrote: > On 8/4/2011 11:27 AM, markspace wrote: >> On 8/4/2011 10:47 AM, Chris Riesbeck wrote: >>> In C++, an >>> overloaded postfix ++ >>> >> See? This is why I'm against any kind of operator overloading in Java. >> Too much stupid out there. > > So what operator should have been used for String concatenation, instead > of overloading "+"? I think the obvious interpretation of my comment should be "user defined operator overloading."
[toc] | [prev] | [next] | [standalone]
| From | Patricia Shanahan <pats@acm.org> |
|---|---|
| Date | 2011-08-04 14:46 -0700 |
| Message-ID | <5-SdnQLc1oSKjqbTnZ2dnUVZ_vOdnZ2d@earthlink.com> |
| In reply to | #6797 |
On 8/4/2011 2:36 PM, markspace wrote: > On 8/4/2011 1:58 PM, Patricia Shanahan wrote: >> On 8/4/2011 11:27 AM, markspace wrote: >>> On 8/4/2011 10:47 AM, Chris Riesbeck wrote: >>>> In C++, an >>>> overloaded postfix ++ >>>> >>> See? This is why I'm against any kind of operator overloading in Java. >>> Too much stupid out there. >> >> So what operator should have been used for String concatenation, instead >> of overloading "+"? > > > I think the obvious interpretation of my comment should be "user defined > operator overloading." > > Why should the appropriateness of an operator overloading be affected by who did it? Patricia
[toc] | [prev] | [next] | [standalone]
| From | RedGrittyBrick <RedGrittyBrick@spamweary.invalid> |
|---|---|
| Date | 2011-08-05 10:09 +0100 |
| Message-ID | <4e3bb343$0$2491$db0fefd9@news.zen.co.uk> |
| In reply to | #6798 |
On 04/08/2011 22:46, Patricia Shanahan wrote: > On 8/4/2011 2:36 PM, markspace wrote: >> On 8/4/2011 1:58 PM, Patricia Shanahan wrote: >>> On 8/4/2011 11:27 AM, markspace wrote: >>>> On 8/4/2011 10:47 AM, Chris Riesbeck wrote: >>>>> In C++, an >>>>> overloaded postfix ++ >>>>> >>>> See? This is why I'm against any kind of operator overloading in Java. >>>> Too much stupid out there. >>> >>> So what operator should have been used for String concatenation, instead >>> of overloading "+"? We could use '.' Then we could use '->' for method invocation. And '::' for class namespace separators (or whatever they are called). ;-) >> I think the obvious interpretation of my comment should be "user defined >> operator overloading." >> >> > > Why should the appropriateness of an operator overloading be affected by > who did it? It shouldn't but I imagine markspace's objection might have been that whilst we all learn about the varied uses of '+' at the start of learning Java, I expect it can be a little perplexing when you encounter a '+' that makes no sense until you find where the original programmer defined an overload of that operator. Even worse might be a '+' that apparently makes sense but where you do not realise that the operator has been overloaded. Is this possible? -- RGB
[toc] | [prev] | [next] | [standalone]
| From | Gene Wirchenko <genew@ocis.net> |
|---|---|
| Date | 2011-08-05 14:46 -0700 |
| Message-ID | <23po371jco79r15913093laroirmsejtgi@4ax.com> |
| In reply to | #6802 |
On Fri, 05 Aug 2011 10:09:22 +0100, RedGrittyBrick
<RedGrittyBrick@spamweary.invalid> wrote:
>On 04/08/2011 22:46, Patricia Shanahan wrote:
[snip]
>> Why should the appropriateness of an operator overloading be affected by
>> who did it?
>It shouldn't but I imagine markspace's objection might have been that
>whilst we all learn about the varied uses of '+' at the start of
>learning Java, I expect it can be a little perplexing when you encounter
>a '+' that makes no sense until you find where the original programmer
>defined an overload of that operator. Even worse might be a '+' that
>apparently makes sense but where you do not realise that the operator
>has been overloaded. Is this possible?
Of course.
Sincerely,
Gene Wirchenko
[toc] | [prev] | [next] | [standalone]
| From | Eric Sosman <esosman@ieee-dot-org.invalid> |
|---|---|
| Date | 2011-08-04 20:51 -0400 |
| Message-ID | <j1ferp$mdm$1@dont-email.me> |
| In reply to | #6796 |
On 8/4/2011 4:58 PM, Patricia Shanahan wrote:
> On 8/4/2011 11:27 AM, markspace wrote:
>> On 8/4/2011 10:47 AM, Chris Riesbeck wrote:
>>> In C++, an
>>> overloaded postfix ++
>>>
>> See? This is why I'm against any kind of operator overloading in Java.
>> Too much stupid out there.
>
> So what operator should have been used for String concatenation, instead
> of overloading "+"?
(Aside: I know of a language that used "||" for this purpose.)
This "overload" is feeble at best: "+" is overloaded six ways,
"-" five, "*", "/", "%", "++", "--", "<", "<=", ">", and ">=" four
each. "==" and "!=" and "=" and "." and "instanceof" are overloaded
to an infinite degree (countable, I think). So what?
--
Eric Sosman
esosman@ieee-dot-org.invalid
[toc] | [prev] | [next] | [standalone]
| From | Tim Slattery <Slattery_T@bls.gov> |
|---|---|
| Date | 2011-08-05 08:38 -0400 |
| Message-ID | <92pn37ds91g71a6pt3jfp85asreecj3nrq@4ax.com> |
| In reply to | #6799 |
Eric Sosman <esosman@ieee-dot-org.invalid> wrote: > (Aside: I know of a language that used "||" for this purpose.) PL/1 used that operator. -- Tim Slattery Slattery_T@bls.gov http://members.cox.net/slatteryt
[toc] | [prev] | [next] | [standalone]
| From | Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> |
|---|---|
| Date | 2011-08-05 10:22 +0000 |
| Message-ID | <slrnj3nh38.6gl.avl@gamma.logic.tuwien.ac.at> |
| In reply to | #6795 |
markspace <-@> wrote: > On 8/4/2011 10:47 AM, Chris Riesbeck wrote: >> In C++, an overloaded postfix ++ ... > See? This is why I'm against any kind of operator overloading in Java. *All* generalizations are bad. This little wart of idiomatic postIncr extended from primitives (where it didn't really matter) to object types (where it does matter) shouldn't be generalized to all operators. (and the other "wart" about overloading << and >> for streams in C++ is just subjective judgement. I don't find it all that bad, myself. It fits well to the look of the symbol indicating direction of data-flow, unlike e.g. mathematical ops, which are "just" convention. ) > Too much stupid out there. Maybe Java just isn't for the masses -- they all have their own mind on coding, not adhering to my own. (*irony*)
[toc] | [prev] | [next] | [standalone]
| From | Lew <lewbloch@gmail.com> |
|---|---|
| Date | 2011-08-10 09:05 -0700 |
| Message-ID | <4562c289-8435-4b71-8d73-6f4320f2cea3@glegroupsg2000goo.googlegroups.com> |
| In reply to | #6781 |
Roedy Green wrote:
> Stefan Ram wrote, quoted or indirectly quoted someone who said :
>> for( int i = 1; i < l.size(); ++i ){ final E e = l.get( 0 ); ... }
>
> This one is clearer. The problem is most people will just glance at it
> and read it as for( int i=0; i<l.zise(); i++ )
>
> I think you mean i++ not ++i.
Huh??
Personally I find the prefix operator more accurately expresses the semantics of the loop.
Not that it makes a whole lot of difference, but why extract the previous value of 'i' for the garbage disposal when it's the subsequent value that's relevant?
There's absolutely nothing wrong with the pre-increment operator and an argument that it's actually superior for this idiom.
--
Lew
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.programmer
csiph-web