Calling Conventions and Pass By Reference

Simon Wistow simon at
Tue Sep 2 21:42:15 BST 2008

On Tue, Sep 02, 2008 at 09:07:18PM +0100, Raphael Mankin said:
> I think that you are confusing call by reference with call by name. With
> call by name every parameter is actually a subroutine that evaluates the
> parameter when you use it, as in Algol 60 of blessed memory.

Sorry, I was being a little confusing.

What I meant to get across was that most programmers think the first way 
(c doesn't change even when a or b does). 

What pass by reference could do is make it much more common to have bugs 
where you accidentally change something out from under your caller, for 
example (albeit contrived)

    my $url = get_url();


    sub check_mirrors_of_url($url) {
        my $check = true;
        for ($mirror in get_mirrors()) {
            $url->host = $mirror; # BZZT! Should have cloned first
            $check &&= HEAD($url);            
    print $url->host; # last mirror, not original

Which will start to lead to defensive programming like
    my $tmp = $url->clone;

which is an awful waste.


More information about the mailing list