Better :)

However, it occurs to me that we need to then check if one list is a subset
of the other, so after the while loop, we would have:

equal = (!iterator.hasNext()
    && !arrayListIterator.hasNext());

This makes the earlier maintenance of 'equal' seem odd to me.  The existing
implementation manages the same login without the intermediate 'equal'
variable management.

Again, personal tastes.  I just opened the source code to have my first full
look at the method, and I think it reads clearly.  Not to say that comments
like "// Scan until we find a difference" and "// If we reached the end of
both lists, they are equal in length and without any differences" wouldn't
help readability a bit.

-T

On Tue, Sep 1, 2009 at 7:35 AM, Martijn Dashorst <[email protected]
> wrote:

> Shaving off some lines :-)
>
> boolean equal = true;
> while (iterator.hasNext() && linkedListIterator.hasNext() && equal) {
>    equal = iterator.next().equals(linkedListIterator.next());
> }
>
> Martijn
>
> On Tue, Sep 1, 2009 at 12:47 PM, Todd Volkert<[email protected]> wrote:
> > I personally don't have a problem with it, but if some find it hard to
> read,
> > then here's the same thing re-phrased:
> >
> > #!{{{
> > boolean equal = true;
> >
> > while (iterator.hasNext()
> >    && linkedListIterator.hasNext()) {
> >    if (!iterator.next().equals(linkedListIterator.next())) {
> >        equal = false;
> >        break;
> >    }
> > }
> >
> > return equal;
> > }}}
> >
> > I prefer the brevity of the former, but that may just be me :)
> >
> > Cheers,
> > -T
> >
> > On Tue, Sep 1, 2009 at 6:38 AM, Martijn Dashorst <
> [email protected]
> >> wrote:
> >
> >> On Tue, Sep 1, 2009 at 11:41 AM, Noel Grandin<[email protected]>
> >> wrote:
> >> >
> >> > It's legal and technically correct Java, but I prefer to write such
> >> > things like this:
> >> >
> >> >   while (iterator.hasNext()) {}
> >> >
> >> > to make it obvious that it's an empty block.
> >> >
> >>
> >> And even better:
> >>
> >> while (iterator.hasNext()) { /* intentionally left blank */ }
> >>
> >> But this type of code does smell pretty awful and should be avoided in
> >> the first place.
> >>
> >> Martijn
> >>
> >
>
>
>
> --
> Become a Wicket expert, learn from the best: http://wicketinaction.com
> Apache Wicket 1.4 increases type safety for web applications
> Get it now: http://www.apache.org/dyn/closer.cgi/wicket/1.4.0
>

Reply via email to