-
Notifications
You must be signed in to change notification settings - Fork 122
Simple symmetric flow of control
Reinhard Budde edited this page Apr 16, 2019
·
1 revision
Sonar complains about this structure. It is used many times.
And Sonar is correct about this:
_the flow of control is hard to understand and dangerous._
public Void visitXxx(Xxx<Void> xxx) {
if ( !xxx.getMode().toString().equals(BlocklyConstants.DEFAULT) ) {
...many-lines-1...
} else {
if ( xxx.getRgbLedColor().getClass().equals(ColorConst.class) ) {
...many-lines-2...
return null;
}
if ( xxx.getRgbLedColor().getClass().equals(Var.class) ) {
...many-lines-3...
return null;
}
...many-lines-4...
}
return null;
}
There are different solutions to this. I propose one. Any solution should
- show the symmetry of the
...many-lines-x...
. All are on the same level - have a
return
at any branch OR have onereturn
at the end of the method. I prefer onereturn
.
public Void visitXxx(Xxx<Void> xxx) {
if ( !xxx.getMode().toString().equals(BlocklyConstants.DEFAULT) ) {
...many-lines-1...
} else if ( xxx.getRgbLedColor().getClass().equals(ColorConst.class) ) {
...many-lines-2...
} else if ( xxx.getRgbLedColor().getClass().equals(Var.class) ) {
...many-lines-3...
} else {
...many-lines-4...
}
return null;
}
Home | Community | Installation | Team
Installation Tutorials
- Instructions to run a openroberta lab server using DOCKER
- Instructions to run the Open Roberta Lab Server natively on ubuntu ‐ not recommended
- Raspberry Pi 2/3/4 and the Open Roberta Lab
- EV3 and leJOS
- EV3 and ev3dev
- Creating the OR leJOS image
- Arduino Create Agent
- Mbed DAL: Generation and automation
Development
-
Workflows
-
Architecture
-
Blockly
-
Software engineering issues
-
Misc
-
Notes on robots
Textual Representation
Contribution
Discussions on future development