I was working on a Simulink model recently and was using Goto
and From
blocks to keep a very busy system from becoming a twisted mess of wires. I was informed that I was not to use Goto
and From
blocks as they are considered bad style (at least, according to my employer).
While I hold that wires should be kept connected whenever possible, I believe that Goto
and From
blocks can significantly improve the readability of a system/subsystem if the model would result in lots of crossed wires otherwise; especially if the blocks can be color-coded (e.g. purple Goto
block goes to all the purple From
blocks).
I'd supply an image of the subsystem I'm working with, but I'm not sure I can put it on here. The subsystem itself has about 12 subsystem blocks (and possibly more later) within it, each with two bus-type outputs. The first output of each subsystem goes to a Bus Creator
block, and the second output of each goes to a second Bus Creator
block. Since the subsystem are aligned vertically and the Bus Creator
s are to the right, this results in many crossed wires. I was using Goto
and From
blocks to clean up the system.
I can supply an image of a smaller, but similar model that I put together for this question.
For a system with on the order of 12 subsystems, this becomes very busy. I was using Goto
and From
blocks to connect the subsystems and the Bus Creator
s without a plethora of crossed wires.
I believe my employer may be carrying the stigma of using goto
statements from text-based languages and applying it to Goto
/From
blocks in Simulink. Generally speaking, is using Goto
and From
blocks in this way (or any way) considered to be bad style?
The Mathworks Automotive Advisory Board has published some modeling guidelines (PDF) that include usage of Goto
/From
. The rules they list are:
Do not have subsystems that are floating, i.e. all inputs / output ports are connected via Goto
s. One of the great things about Simulink is the ability to determine signal flow with only a cursory visual inspection, do not destroy this by linking everything with Goto
s. At least have one feed-forward and one feedback loop between subsystems connected by signal lines.
The second guideline is about the scope of the Goto
tag; keep the visibility local
as much as possible.
scoped
is acceptable also as long as you're not using the matching From
more than a couple of levels downstream from the Goto
. I've yet to come across a legitimate need for a global Goto
tag. So, all Goto
usage isn't bad, and you're right that it can improve readability in some cases. That being said, I don't think Gotos are justified for the picture above. I realize it is just an example, but I should point out that if the buses being created are virtual that order of the inputs at the creator doesn't matter, and rearranging Bus Create and Mux block inputs can work wonders for readability.
The problem with the guidelines above are that there's room for bending them, and developers on your team might do just that. Even if everyone is diligent about following them at first, you may run afoul of these guidelines one day, a long time from now, when you redraw that section of the model for refining / adding functionality. Rearranging inputs and outputs can be especially irritating in middle of implementing some cool new feature. That may be the reason your employer chose to impose a blanket ban. It is inconvenient in some cases, but is easier to enforce.