Shop OBEX P1 Docs P2 Docs Learn Events
Java language help needed.(Not any more) — Parallax Forums

Java language help needed.(Not any more)

diafysaldiafysal Posts: 92
edited 2005-09-20 15:45 in General Discussion
Java language help needed.

Hi
I'm going to use the uM-FPU IDE eventually.
But first I read through some of the code from www.micromegacorp.com/downloads/software/uMFPU-V2-Javelin.zip

I am not that good at Java so I wonder if someone could have an opinion.

I read this from Fpu.java (I2C):
  public static boolean reset(I2C i2cBus, int devAddr) {
    bus = bus;
    if (devAddr == 0)
      addr = I2C_ADDR;
    else
      addr = devAddr;
    return(reset());
  }



And compared with PCF8574.java (io class):
  public PCF8574 (I2C bus, int devAddr, int dirs) {
    this.bus = bus;
    this.addr = this.addr | ((devAddr & 0x07) << 1);
    this.dirs = dirs;
  }



Is Fpu.java really right ? (“bus” , “this.&#8221[noparse];)[/noparse]

Post Edited (diafysal) : 9/21/2005 8:34:52 PM GMT

Comments

  • allanlane5allanlane5 Posts: 3,815
    edited 2005-09-20 15:20
    The big difference between the two is that the PCF8574 constructor is using for parameter names the same names as the class property names. Thus the constructor has to use the 'this' reference to reduce the ambiguity.

    The 'reset' method actually is incorrect -- the "bus = bus;" line should be "bus = i2cBus". Otherwise, it doesn't HAVE to use the 'this' reference, but it could.

    Personally, whenever I'm referring to a 'native' class property, I ALWAYS use the 'this' reference to make it crystal clear what's going on. I don't know that it would have saved the author of 'reset' above, though.
  • diafysaldiafysal Posts: 92
    edited 2005-09-20 15:45
    Thank you for the reply.
    I have notified the author.

    (edit)
    The code/site is updated.

    Post Edited (diafysal) : 9/21/2005 2:42:21 PM GMT
Sign In or Register to comment.