Fortran goto in java

Yes, I looked at different ways to implement GOTO in java, but here is the real world: I need one of the last fortran LAPACK procedures converted to java, see http://www.netlib.org/lapack/timing/eig/eigsrc/dlasq3 .f for example :.

10 CONTINUE IF( N0.LT.I0 ) $ RETURN IF( N0.EQ.I0 ) $ GO TO 20 NN = 4*N0 + PP IF( N0.EQ.( I0+1 ) ) $ GO TO 40 OPS = OPS + DBLE( 3 ) IF( Z( NN-5 ).GT.TOL2*( SIGMA+Z( NN-3 ) ) .AND. $ Z( NN-2*PP-4 ).GT.TOL2*Z( NN-7 ) ) $ GO TO 30 20 CONTINUE fortran code ... GO TO 10 30 CONTINUE OPS = OPS + DBLE( 2 ) IF( Z( NN-9 ).GT.TOL2*SIGMA .AND. $ Z( NN-2*PP-8 ).GT.TOL2*Z( NN-11 ) ) $ GO TO 50 40 CONTINUE fortran code ... GO TO 10 50 CONTINUE 

What will be the “standard” way to deal with all possible goto?

+4
source share
2 answers

GOTO are considered anti-patterns. You should never try to convert it directly to Java without revising the code.

For example, when you see a label for GOTO, this is most likely a sign that this code will be reused. Should it be included in a method that will be called again in the future? Approach a new design using OO, instead of using the same process as in FORTRAN.

Java really works in the real world without goto.

+3
source

The best way to handle this is to assemble each logical unit as a partition and create a state diagram for the entire function.

Do not forget that a fall through the beginning of a state is considered a transition and should be considered as such. When you break them down into state transitions, you can start to see where they can be turned into several functions using recursion or iteration, where necessary.

Now I fully admit that I do not understand the function or what it does or should do, but this was the first attempt to draw up a state diagram to give you an idea of ​​what I mean. Pay attention to the cycle at 80 , you probably need a cycle. Note that 10 and 100 are your only return states. Please note that when you go from 30 to 50, there is no turning back. This indicates that 50+ can be its own isolated function, while 10-40 is its own function with a loop, which when it reaches 30 says return functionRepresenting50Pluss(...)

enter image description here

Just note that the filled squares on some state transitions indicate that this transition is guaranteed to be selected if no other transition is made from the state. Note that it does not exist at 80 because I could not really decide if 80 or 90 was a guaranteed destination. Could there be something for 80 cycles forever? Without understanding the function, I can no longer say.

+6
source

All Articles