🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.modula2
Article #1455

Re: Compilier Problems

#1455
From: Patrick J Draper
Date: Thu, 06 Dec 1990 20:34
42 lines
2458 bytes
In article <INFO-M2%90120607362197@UCF1VM.BITNET> Modula2 List <INFO-M2%UCF1VM.BITNET@ucf1vm.cc.ucf.edu> writes:
>>FST allows complete structures etc.. through var parameters ...
>
>Returning function results through var parameters? A practice somewhat
>frowned upon! Write a procedure instead.
>
>Rob Griffiths
>Computing Department
>The Open University


Suppose you have a procedure that looks up a record in an index and
returns the record number, a common database procedure. Both the
database and index might have to be changed in the function, and need to
be returned through variable parameters.

example:

PROCEDURE ReturnKeyRecord (VAR db : DB; 
                           VAR index : INDEX;
                           key : ARRAY OF CHAR) : LONGCARD;

This procedure accepts two types that hold all relevant information
about the database and index files, such as record length, field names,
etc. The return value is the record in the database where the key was
found. Both db and index are modified by some aspect of this function
(when the key is found, both the db and index file pointers are changed)
and MUST be returned or the program will crash.

The ability to return values through both the parameter and return value
is a feature of M2 because it is intuitive, and is also a safe
mechanism. The example I have given above is much more logical to me
than the alternative form where a variable called record is a parameter.
When I look at the function, I KNOW that the primary focus of the
function is to return a LONGCARD based on the parameters given.


------------------------------------------------------------------------
Patrick Draper              In times like these it is helpful to
buster.cps.msu.edu          remember that there have always been
                            times like these.
------------------------------------------------------------------------
Technical Details
Message-ID: <1990Dec6.203456.9301@msuinfo.cl.msu.edu>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!umich!sharkey!msuinfo!news
References: <INFO-M2%90120607362197@UCF1VM.BITNET>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!umich!sharkey!msuinfo!news
From: draper@buster.cps.msu.edu (Patrick J Draper)
Newsgroups: comp.lang.modula2
Subject: Re: Compilier Problems
Message-ID: <1990Dec6.203456.9301@msuinfo.cl.msu.edu>
Date: 6 Dec 90 20:34:56 GMT
References: <INFO-M2%90120607362197@UCF1VM.BITNET>
Sender: news@msuinfo.cl.msu.edu
Reply-To: draper@buster.cps.msu.edu (Patrick J Draper)
Organization: Dept. of Computer Science, Michigan State University
Lines: 42