forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Snippets of Wisdom (?) #1 - GOTO ...

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General
View previous topic :: View next topic  
Author Message
John-Silver



Joined: 30 Jul 2013
Posts: 1520
Location: Aerospace Valley

PostPosted: Wed Sep 19, 2018 9:08 am    Post subject: Snippets of Wisdom (?) #1 - GOTO ... Reply with quote

Browsing a book recently, under a section entitled "Some hints on how to improve your programming style", I came across this STATEMENT ...

Quote:
The GOTO statementshouldnever be used, under any circumstances.


which in general terms is clearly nonsense, no ? if not, why ? or is it just 'style'-ish not to use it.

Maybe this statement of supposed 'knowledge' (it is in a book after all) just needs some qualification in terms of it's applicability.

(It's a bit like the never ending IMPLICIT NONE debate I guess)

In the past I have used the IF/GOTO profusely and it doesn't seem to have done me any harm.
_________________
''Computers (HAL and MARVIN excepted) are incredibly rigid. They question nothing. Especially input data.Human beings are incredibly trusting of computers and don't check input data. Together cocking up even the simplest calculation ... Smile "
Back to top
View user's profile Send private message
JohnCampbell



Joined: 16 Feb 2006
Posts: 2554
Location: Sydney

PostPosted: Wed Sep 19, 2018 1:04 pm    Post subject: Reply with quote

Excessive use of GOTO can create code that is difficult to read, which was more common pre F90 and F77.
Alternatives of CYCLE and EXIT in DO loops and IF ... THEN ... ELSE ... END IF can create more readable code.
For error condition recovery, GOTO can be very practical.

However, I do find the quote to be extreme and an indication of an author I would not recommend. Unfortunately, there are a number of authors in this group.
Back to top
View user's profile Send private message
Robert



Joined: 29 Nov 2006
Posts: 444
Location: Manchester

PostPosted: Thu Sep 20, 2018 11:48 am    Post subject: Reply with quote

I suppose it is one of those things that if people avoid GOTOs they will not get into trouble using them. They may well tie themselves up in all sort of problems but at least the GOTO will not get the blame Smile

It is a bit like 'never refreeze food'. In general it is good advice but there are situations where it is okay to do so.
Back to top
View user's profile Send private message Visit poster's website
John-Silver



Joined: 30 Jul 2013
Posts: 1520
Location: Aerospace Valley

PostPosted: Sat Sep 22, 2018 2:13 am    Post subject: Reply with quote

a good analogy ... or maybe not actually because using go to's never killed any program.
I've read a few opinions on the subject and the gist seems to be that without goto's the understanding of the program flow is better/easier.
that seems to be the only dowmìner floating about - which is fine if you're a programmer working with large programs I suppose, but for average joe user it all seems a bit OTT to suggest goto is a no go, even sometimes.
_________________
''Computers (HAL and MARVIN excepted) are incredibly rigid. They question nothing. Especially input data.Human beings are incredibly trusting of computers and don't check input data. Together cocking up even the simplest calculation ... Smile "
Back to top
View user's profile Send private message
mecej4



Joined: 31 Oct 2006
Posts: 1885

PostPosted: Sat Sep 22, 2018 10:07 am    Post subject: Re: Reply with quote

John-Silver wrote:
...using go to's never killed any program.


May be so, but imagine the number of programmers that got almost killed. In fact, the COME FROM statement was proposed several times over the years as a partial solution to the problem.

Last week, I worked with an old (1980-ish) program that is almost entirely GOTO based; see www.netlib.org/a/cdfcor . This program triggered a bug that has existed from FTN95 5.3 (possibly earlier, that is the oldest version that I have) to FTN95 8.3. I suspected the bug to be located in that posted code, rather than in the compiler

Try debugging that CDFCOR beast, as a rite of passage.

There was a paper published with the title GOTO Considered Harmful and a subsequent paper, "GOTO Considered Harmful" Considered Harmful, see https://en.wikipedia.org/wiki/Considered_harmful .


Last edited by mecej4 on Sat Sep 22, 2018 1:23 pm; edited 1 time in total
Back to top
View user's profile Send private message
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2388
Location: Yateley, Hants, UK

PostPosted: Sat Sep 22, 2018 12:11 pm    Post subject: Reply with quote

Once again, dear Mecej4, a NETLIB link that doesn’t work.

When I read a statement like the one quoted in the original post, I am acutely aware of the position of its author: he/she hates the FORTRAN that is, and wishes to change it to something that it isn’t, and never was.

I’m quite prepared to accept a GO TO (which I always write with the internal space, as that is more like English) because it tells me where I’m going to. I once had to follow another (appallingly bad) driver (incidentally my sister-in-law) who took a roundabout route to get somewhere I knew extremely well – in fact, on the other side of the road from the building where I did my undergraduate studies. If only I had been supplied the address, I could have got there more quickly and safely.

I was also happy to pay a mortgage when I knew the final payment date in advance: I would have been less happy to “go on paying until we tell you to stop”.

Complete disapproval of GO TO is also linked to complete disapproval of statement numbers. Actually, statement numbers can be useful – they are outdents, after all, and if you like indents you probably ought to like outdents as well – but in the case of the NETLIB stuff we aren’t seeing easily readable code in the first instance. The previous example you (Mecej4) showed was horrible and virtually unreadable, so I am not the least disappointed that the link gives me a 404.

I like to write shortish subprograms, and use statement numbers that ascend through the code with a stride of 10, i.e, 10, 20, etc. If the subprogram is experimental, and by that, I mean I expect to have to ‘develop’ it, I take a bigger stride, usually 20, but sometimes more. This leaves free numbers when things are inserted, and then, I always know which bits are ‘fixes’. When I know the routine works, I may renumber it, or leave well alone. In any case, the statement numbers always ascend.
I have seen codes where the whole program is numbered in ascending statement numbers through all the subprograms, whereas mine restart in each routine.

My style is to group formats at the end of each routine, with a numbering style that is different to that for the executable statements.

Past programming had to use more statement numbers than we would today, because of the nature of the IF statement, only available as an arithmetic IF for many compilers. Even that has its uses. Also, there were less statement numbers at loop ends, and less CONTINUEs, because nested loops could end on a common numbered executable statement.

If the original opinion had been
Quote:
The GOTO statement should be used sparingly
then I would agree, just as I would suggest that statement numbers should be used sparingly, and be written in a sensible sequence.

Bansturbators (as I believe they are now called) are usually complete plonkers, and as I have a surfeit of books, I’d probably have used the pages of the one quoted to start a barbecue, but even then, on the principle that stopped clocks are right twice a day, perhaps it was worth reading in the hope, rather than the expectation, that there could be hidden gems within it.

Eddie

PS Why are there so many Bansturbators on the Fortran Standards Committee?

PPS RETURN lies in the same family as CYCLE and EXIT, in that in none of them is it particularly obvious where one goes next.
Back to top
View user's profile Send private message
mecej4



Joined: 31 Oct 2006
Posts: 1885

PostPosted: Sat Sep 22, 2018 1:27 pm    Post subject: Re: Reply with quote

LitusSaxonicum wrote:
Once again, dear Mecej4, a NETLIB link that doesn’t work.

Sorry, fixed. I have to remind myself to type a space after a URL at the end of a sentence, before the period (fullstop).

The problem with that particular code is that it is unsparing in its use of statement numbers and GO TO statements. Many blocks are actually DO and DO WHILE constructs that have been implemented using GO TO. One problem with having a large set of statement numbers is that, to the average reader, the number of potential execution sequences may look frighteningly large.

I agree with you that sometimes a few simple GO TO statements can make a code readable rather than by use of statements such as CYCLE <do-construct-name> and EXIT <do-construct-name>.


Last edited by mecej4 on Sat Sep 22, 2018 1:46 pm; edited 1 time in total
Back to top
View user's profile Send private message
mecej4



Joined: 31 Oct 2006
Posts: 1885

PostPosted: Sat Sep 22, 2018 1:33 pm    Post subject: Re: Reply with quote

LitusSaxonicum wrote:
If only I had been supplied the address, I could have got there more quickly and safely.


Eddie, you're normal! Please note that there is at least one book about that:

https://www.amazon.com/Dont-Listen-Women-Cant-Read/dp/0752846191
Back to top
View user's profile Send private message
JohnCampbell



Joined: 16 Feb 2006
Posts: 2554
Location: Sydney

PostPosted: Sat Sep 22, 2018 2:21 pm    Post subject: Reply with quote

mecej4,

The cdfcor.for link you provided is a very old version of FORTRAN which does not support logical variables or expressions.
This is similar to an IBM 1130 FORTRAN, even before McCracken's FORTRAN 66.
When I first started working, the company I worked for had an 1130. I refused to use this FORTRAN and used a Pr1me 300 bureau which had FORTRAN that included logical variables. Fortunately we soon upgraded to a Pr1me.
The argument against GOTO could vary, depending on which Fortran you consider, however I agree that banning is in the land of the plonkers !
Back to top
View user's profile Send private message
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2388
Location: Yateley, Hants, UK

PostPosted: Sat Sep 22, 2018 2:27 pm    Post subject: Reply with quote

Hi Mecej4,

I had a look at the book, where the Kindle version is affordable and doesn't take up shelf space. I see it's not just about reading maps and not listening, but also about parallel parking.

Actually, to contradict the book, my wife is better at parallel parking than I am, because after having had my alloy wheels refurbished at colossal cost, and then subsequently having had 2 of them redone to weld up cracks induced by driving over potholes, I can't bear to go too close to London's strong and highly abrasive granite kerbs, especially as many local roads have excessive camber. She simply doesn't care - especially in my car!

The NETLIB stuff is truly appalling.

Eddie

PS To add to John's comment, when I had to use an 1130, bureau services didn't exist, and neither did Pr1me. The Prime 300 was launched 3 or 4 years after I stopped having to use the 1130.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group