I bet many of you have heard of the famous “consider harmful” article (PDF, 609 KB) from Edsger W. Dijkstra. Luckily, Fortran has come a long way since those days, and now has good support for structured programming making go to obsolete more or less. (The Craft of Coding blog has several insightful essays on go to.)
So what’s the purpose of this thread? Use this thread to share the worst cases of GOTO out in the wild. Nasty snippets using arithmetic if are also allowed.
Image source: The Craft of Coding - Is goto evil?
We are looking for the go to’s that deserve Dijkstra’s criticism; the ones which suck all the joy out of reading code . The more -like and hard to refactor the better. Feel free to also share pretty re-engineered (untangled) snippets, in case you have them.
You can think of this thread as a kind of memorial - a place of contemplation and warning , similar to the memorials erected after wars or the plague . Simultaneously, it’s also a tribute to the ingenious Fortran programmers who did the best they could with what was available.
To start off the thread, here is a snippet I’m currently trying to untangle from a sparse LU factorization routine,
if(iflag(4).ne.1)go to 480
if(lfr.gt.ha(r1,9))ha(r1,9)=lfr
if(lfc.gt.ha(r2,10))ha(r2,10)=lfc
480 if(i1.eq.1)go to 490
if(snr(i1-1).eq.0)go to 600
490 if(rr2.eq.nn)go to 500
if(snr(rr2+1).eq.0)go to 580
500 r10=nn-lfr
C
C ... 60 lines later ...
C
go to 590
580 rr2=rr2+1
ha(r1,3)=rr2
l1=rr2
if(rr2.le.r4)go to 610
590 r4=rr2
if(r4.lt.nn)snr(r4+1)=0
go to 610
600 rr1=rr1-1
i1=i1-1
ha(r1,1)=i1
ha(r1,2)=rr1
l1=rr1
snr(i1)=snr(l1)
a(i1)=a(l1)
610 a(l1)=tol3