Usenet comp.sys.dec (1990-2013)
 help / color / mirror / Atom feed
From: mathog@seqaxp.bio.caltech.edu
Subject: Re: DCL questions
Date: 1997/06/13	[thread overview]
Message-ID: <5nrti7$dj3@gap.cco.caltech.edu> (raw)
In-Reply-To: 5npk1f$ads$2@netty.york.ac.uk


In article <5npk1f$ads$2@netty.york.ac.uk>, rw106@york.ac.uk (Ross Wintle) writes:
>Hi,
>
>I'm just curious as to what the best way of writing modular programs in
>DCL is.  I work in my vacations for a company that use DCL and I really
>want to be able to write modular code.

Depends on what you mean by "modular".  If you mean different functions are 
stored in different files, and you access them via @filename, you can do 
that, but I try not to. It isn't that it doesn't work, it's just that you 
have to be sure that none of the pieces ever change names, get moved, and 
so forth.  The main reason for breaking code out like this is so that you 
can reuse it in the context of different DCL procedures.  I do have a few
routines around that I reuse verbatim, and they do live in separate files,
but that isn't the way I normally "reuse" DCL.  Rather, I copy the original
and modify it.  There is no inheritance, but it doesn't matter, since they
aren't complicated enough to warrant it. 

If, on the other hand, by modular you mean "structured", well, then DCL is
adequate.  You have: 

$ if (condition1)
$ then
$    if (condition2)
$    then
$    else
$    endif
$ else
$ endif

and also named subroutines

$!    declare a subroutine "PROCESS_IT"
$ PROCESS_IT: SUBROUTINE
$!    do stuff
$ EXIT
$ ENDSUBROUTINE
$!
$!    use the subroutine
$!
$ call PROCESS_IT "first parameter" "second parameter"

and labeled subroutines:

$ I_AM_SUB:
$!  do stuff, set status [status] is optional
$   return [status]
$!
$! call it, test the return status
$!
$ gosub I_AM_SUB
$ if(.not. $status)then 

There are a few differences between the two types of subroutines, the first 
one is essentially like doing:

@external p1 p2 p3 

as parameters show up inside as P1,P2, etc.  Whereas in the second 
subroutine form you still have access to the variables defined elsewhere in 
the procedure.  The first form is more "structured", if you will, since it
does a better job of isolating the subroutine code from the rest of the 
procedure.

That's about it for the structures provided.  If you can get over the "goto
is evil" mentality, and force yourself to code cleanly, you can easily
implement any other sort of flow control that you might desire. The one
programming gotcha is that you have to be sure your labels are unique. 

For instance, there is no explicit loop structure, you have to use 

  GOTO label

but the end result is the same: 

$!
$! do while, top exit
$!
$ top:
$ if(.not. condition) then goto loopexit
$!    do stuff
$!    set/unset condition
$ goto top
$ loopexit:

Similarly, there is no explicit structure:

  if
  else if
  else if
  else if
  ...
  else
  end if

Again, you can implement one using goto's

$if (condition1)
$then
$! do stuff
$  goto endstruct
$endif
$!
$if (condition2)
$then
$! do other stuff
$  goto endstruct
$endif
$!
$! ... as many conditions as required, then the
$! else part
$!
$! do whatever should be in "else"
$endstruct:

You can also use computed gotos.  This comes up fairly often, as when you
are processing data that has a finite number of states, each corresponding
to an action, that can be numbered from 1-N.  In this code none of the
needed safety checks are shown! 

$! val is a STRING holding an integer 1<->30
$ goingto = "UNIQUE" + val
$ goto goingto
$ UNIQUE1:
$!  code
$   goto endUNIQUE
$ UNIQUE2:
$!  code
$   goto endUNIQUE
...
$ UNIQUE30:
$!  code
$!
$ endUNIQUE:

Another variant of this uses the f$element function to pick out the label 
names, here VAL is an INTEGER from 0<->3, again safety code not shown

$ labels="first,second,third,fourth"
$ goingto = f$element(VAL,",",labels)
$ goto goingto
$ first:
$! etc.

For more information, have a look at the "OpenVMS User's Manual", or

  http://seqaxp.bio.caltech.edu:8000/www/vms_sheet.html             
  http://seqaxp.bio.caltech.edu:8000/www/vms_beginners_faq.html   

>
>To me it doesn't seem like DCL is meant for any kind of serious
>programming, it's a scripting language that I personally would use to
>write helpful system utilities and leave the proper programming to a
>proper programming language.

Depends on what you're after.  If it is anything big, and speed is important,
than you are correct, use C, Fortran, Cobol or whatever.  If you have to 
deal with strings longer than a thousand or so characters, then DCL is 
inappropriate.  However, if it runs once and a while, and speed isn't very
important, then DCL is fine.   If you need to speed up your DCL, you can 
strip all of the comment lines and have an "executable" version and a 
"source" version, ie: 

  $ search/match=nor/out=fastone.com slowone.com "$!"

There is also a commercial product that compiles DCL to Fortran, if you
really need a big speed up. 

Regards,

David Mathog
mathog@seqaxp.bio.caltech.edu
Manager, sequence analysis facility, biology division, Caltech 
**************************************************************************
*Affordable VMS? See:  http://seqaxp.bio.caltech.edu:8000/www/pcvms.html *
**************************************************************************



  reply	other threads:[~1997-06-13  4:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-06-12  4:00 DCL questions Ross Wintle
1997-06-13  4:00 ` mathog [this message]
1997-06-16  4:00 ` Stephen Hoff Hoffman
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox