Re: Proper way to return a string



In article <slrnep5g8k.3020.Jeremy@xxxxxxxxxxxxxxxxxxx>,
Jeremy <my-first-name@xxxxxxxxxx> writes:
I am wrapping (because I cannot find it already done, if you know of one
that exists let me know!) libpq for PostgreSQL database access. A
function, PQresStatus returns a string version of the result status. In
returning this to Fortran, can I return it from a function call? Should
I? Should I use a subroutine, I know how to easily deal with giving
string information back that way.

I guess I am still trying to understand when I should use a function
and when I should use a subroutine with inout/out parameters.

The following is my opinion. I'm sure others here will prefer
a different set of rules.

For numeric and logical types, if the routine computes a *single*
result, then I use a function. The function can take zero or
more arguments. If more than one result is to be returned, then
I use a subroutine. The distinction gets blurred when one starts
to consider array operations where the result is an array. Is the
array a single result or is it a collection several individual
elements?

For strings, I always use subroutines. I don't remember why I
developed that habit. It is just something I do.

There are, of course, exceptions to the rules. Here, one should
provide good comments, so the exceptions are well understood.

In the end, one should develop a style and stick with it.

--
Steve
http://troutmask.apl.washington.edu/~kargl/
.



Relevant Pages

  • Re: String Array Insert
    ... I should have renamed the second subroutine differently from the first one I posted... ... Dim Position As Long ... Dim Combined As String ... following code, albeit somewhat slower than my original one-liner (which won't matter unless you are using this in a large loop against a very large array), will insert one or more empty elements at the element index number specified in the 2nd optional argument. ...
    (microsoft.public.vb.general.discussion)
  • whats OOPs jargons and complexities?
    ... in advanced languages such as LISP family, it is not uncommon to define ... subroutine f1 ... For example, in Java, a string is a class String. ...
    (comp.lang.perl.misc)
  • whats OOPs jargons and complexities?
    ... in advanced languages such as LISP family, it is not uncommon to define ... subroutine f1 ... For example, in Java, a string is a class String. ...
    (comp.lang.c)
  • whats OOPs jargons and complexities?
    ... in advanced languages such as LISP family, it is not uncommon to define ... subroutine f1 ... For example, in Java, a string is a class String. ...
    (comp.lang.python)
  • whats OOPs jargons and complexities?
    ... in advanced languages such as LISP family, it is not uncommon to define ... subroutine f1 ... For example, in Java, a string is a class String. ...
    (comp.lang.lisp)