Menu

#15 Efficient convenience methods for IfThenElseBlock, LoopBlock

open
nobody
None
5
2007-01-22
2007-01-22
No

In IfThenElseBlock, there is no obvious mechanism for checking whether it has an "else" part. The only way is to check whether getSubBlocks() returns an array of length 1 or 2, but that allocates memory on every call. That's why it would be nice to have the following method added to IfThenElseBlock:

public boolean hasElse() {
return elseBlock != null;
}

Along those same lines, you can't obtain a handle to a LoopBlock's body without allocating memory (on each call to getSubBlocks()). Therefore, it would be nice to have the following method in LoopBlock.java:

public StructuredBlock getBody() {
return bodyBlock;
}

Thanks!

Discussion

  • Trevor Harmon

    Trevor Harmon - 2007-01-22

    Logged In: YES
    user_id=720008
    Originator: YES

    I forgot a couple more. IfThenElseBlock has setters but no getters for thenBlock and elseBlock. You could obtain them with getSubBlocks(), but again, that allocates memory on each call. Instead, it would be nice to see the following:

    public StructuredBlock getThenBlock() {
    return thenBlock;
    }

    public StructuredBlock getElseBlock() {
    return elseBlock;
    }

    Not only are these more efficient than getSubBlocks(), but they also make the calling code more readable.

     
  • Trevor Harmon

    Trevor Harmon - 2007-01-24

    Logged In: YES
    user_id=720008
    Originator: YES

    It would be nice to have a few more accessor methods in LoopBlock:

    public Expression getInitInstr() {
    return initInstr;
    }

    public InstructionBlock getInitBlock() {
    return initBlock;
    }

    public Expression getIncrInstr() {
    return incrInstr;
    }

    public InstructionBlock getIncrBlock() {
    return incrBlock;
    }

    There isn't any memory allocation problem here, but the methods are needed for public access to some important fields.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.