Menu

#66 Positional Iterator

Long-term
closed
rules (229)
5
2012-10-07
2002-08-29
No

I always get the willies when I see something like this:

public void foo(Iterator iter) {
Object ob1 = iter.next();
Object ob2 = iter.next();
Object ob3 = iter.next();
}

Where ob1, ob2 and ob3 really have nothing to do with one
another.

Its almost the same as doing this in C.

struct stuff {
int a;
int b;
int c;
}

struct stuff myStuff;

int A = myStuff[0];
int B = myStuff[1];
int C = myStuff[2];

Basically, because we know the structure of the struct,
we know
the constants of the Array.

We should probably check for things like this. . .

Discussion

  • Tom Copeland

    Tom Copeland - 2002-09-03

    Logged In: YES
    user_id=5159

    This one

    -could be done on both Iterators and Enumerations
    -would go in the design ruleset

     
  • Tom Copeland

    Tom Copeland - 2002-09-04

    Logged In: YES
    user_id=5159

    Looks like fun. Working on it now.

     
  • Tom Copeland

    Tom Copeland - 2002-09-04

    Logged In: YES
    user_id=5159

    Whew, this is not particularly easy. I should be able to get
    one or two easy cases done, though.

    Tom

     
  • Tom Copeland

    Tom Copeland - 2002-09-04

    Logged In: YES
    user_id=5159

    This gets tough because you have to do some data flow
    analysis in case like this:

    public class Foo {
     private int baz = true;
     public void bar(Iterator i) {
      Object x = null;
      while (i.hasNext()) {
       if (baz) {
        x = i.next();
       } else {
        x = new Runnable() {public void run() {Object bif = i.next
    

    ();}}
    }
    }
    }
    }

    So it's in the experimental ruleset for future contemplation.

     

Log in to post a comment.

MongoDB Logo MongoDB