Re: use 'go to' doing some case studies and induced problems
- From: Catherine Rees Lay <spamtrap@xxxxxxxxxxxxxx>
- Date: Thu, 20 Jul 2006 11:18:23 +0100
Mike wrote:
Hi,
Let's say there will be some case studies after the main program.
Usually, I do this:
program main
go to 100 !case 1
go to 200 !case 2
go to 300 !sensitivity study..
....
100 continue
case 1......
stop ' case 1'
.....
Sometimes, these case studies are not so worthy of writing them as
subroutines. Furthermore, it takes time to find the varialbes or
modules declared or used in the subroutine . I'd like to know the
answer quickly. Hence I write a lot of go to XXX. Each of them go to
a small case study. Oh, yes. Sometimes I can jump to the case study
directly to prevent from reruning. This is the advantage. However,
there will be drawbacks. One of them is that I usually forgot if some
parameters are initilized or set.
My questions are
(1) what will you do if you want to do some case studies in the end of
main program without writing it as subroutines/functions ? Will you
use ' go to '?
(2) How to prevent from forgetting initilizations of varaibles if one
use 'go to'?
Any suggestion is appreciated.
Mike
1) If for some reason I really didn't want a separate routine with an argument list, I'd use an internal subroutine. I've done this where I've been splitting up old code that had
if (case1) then
<lots of lines>
elseif (case2) then
<lots of lines>
elseif...
It's very rare that I use it on new code.
These days I almost never use goto, and certainly not in the case you describe. Anything so short that it's not worth making a subroutine for (say, less than 10 lines), I'd put inline in the code. If it's worth splitting out, then why not use the facilities the language has for that - i.e. subroutines?
2) A compiler which tells you at run-time if an uninitialised variable is used is a huge timesaver.
You really have to think about your comment "Furthermore, it takes time to find the varialbes or modules declared or used in the subroutine . I'd like to know the answer quickly."
I'd have to say, this sounds like it could easily lead to GIGO (garbage in, garbage out) when you miss something in the logic. If you're lucky, your answer will be wildly wrong and you'll notice. If you're unlucky, it'll be plausible but wrong. Any method will only work correctly if you also make sure the values in the variables are correct. Writing subroutines makes you think about the logic. The extra time is worth it.
Catherine.
.
- References:
- Prev by Date: Re: Segmentation Fault without write?
- Next by Date: Re: writing output listing onto screen (or not) and onto file
- Previous by thread: Re: use 'go to' doing some case studies and induced problems
- Next by thread: Re: use 'go to' doing some case studies and induced problems
- Index(es):
Relevant Pages
|