Re: pass args by value or by ref but not both

Derek Robert Price <[email protected]> Wed, 22 Jan 2003 14:33:43 -0500
Newsgroups gmane.comp.tex.texi2html.devel
Organization Ximbiot <http://ximbiot.com>
Message-ID <[email protected]>
Dumas Patrice wrote:

>Hi,
>
>Some subroutines are evaluated for their side effects, with args passed by
>address, like normalise_node, but somtimes the return value is used, too.
>I think that the code would be more clear if there was only one way to
>call the subroutine.
>
>I also think that it should be better if it was made more clear whether
>the args are passed by value or by adress. For example:
>
>sub clean_name
>{
>    local ($_);
>    $_ = &remove_style($_[0]);
>    &unprotect_texi;
>    return $_;
>}
>
>Here it is not so clear whther there are side effects or not, one has to
>look at remove_style. If the function was written
>sub clean_name
>{
>    local ($_);
>    $_ = &remove_style(shift);
>    &unprotect_texi;
>    return $_;
>}
>things would be more clear. And giving formal names could even improve
>readability :
>  
>

I didn't realize that &shift would break a call-by-reference, but if it 
does, then go ahead!  

>sub clean_name
>{
>    local ($_);
>    my $text = shift;
>    $_ = &remove_style($text);
>    &unprotect_texi;
>    return $_;
>}
>
>In fact here this is not really needed but for other functions it could 
>be nice.
>
>Do you want to keep the code as it is or should I go on and modify that ?
>
>Pat
>  
>

Same thing.  If &shift breaks the call-by-reference, then either 
approach is fine with me.

Derek

-- 
                *8^)

Email: [email protected]

Get CVS support at <http://ximbiot.com>!
-- 
I will not cut corners.
"   "   "   "     "
"   "   "   "     "   ...

          - Bart Simpson on chalkboard, _The Simpsons_