So the argument should have actually been against the use of line labels, not the GOTO command specifically (as many other commands also allow, or use line labels)...rcrsn51 wrote:Here is the test for a well-written block of code. Start at Line 1 and read sequentially down the page to Line N. At that point, after looking at each line once, do you have a complete understanding of what the code does? If you do, the code is well-written.
This is the point that Dijkstra is making. It is hard enough to make the connection between the static lines of programming code and the real-word dynamic process that they represent. The use of elements like goto's and line labels makes it even more difficult.
And, just in writing in any language, the formatting, grammar and correct vocabulary all contribute to "readability" of an article, or a programming structure. If I wrote this text with no formatting, capitalization or punctuation, it would be much more difficult to read.The original programmer may be able to follow the logic perfectly well, but he is rarely the only audience.
Line labels, just as GOTOs, should be used sparingly (for one, if you use too many labels, you will forget which ones you have used, as you edit and re-edit a piece of code -- then you have cross-linked branches).
Comments and explanations throughout the code help considerably.
Some years ago, I recall trying to debug a piece of code. About 400 lines into the code, I find a single comment "C We now invert the matrix"... So I go back to the top, and there are no arrays defined at all. I go back down, and discover that the "matrix" is all stored in single variables: w,x,y,z,q,r,s,t,e,... WTF!!!! Yes, it was also extreme "goto" spaghetti code... (I believe that is also where I saw the "If(N) 10, 20, 30..." code).
But for our discussion, if I had a more complex problem than simple text substitution, I would likely use a "10 read() >> goto 10" to load the indeterminate data array (I still must over-specify the array size, under most modern compilers -- at one point, the DEC/VAX compiler permitted the array size be determined inside the program, so the array was expanded or contracted internally, and could be defined through a variable...yes, strange). However, once loaded, I now know exactly how large my array is, so all subsequent calculations can be explicit do loops of "i = 1, size" -- and no further no line labels needed (though I almost always put a line label on the "end" statement, as a termination point).