Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Journal of markjugg (792)

Thursday August 31, 2006
06:25 PM

CGI::App to Perl6: Another improvement for references

[ #30828 ]
Earlier I wrote about how references are gone in Perl6. However, subroutine signature Perl6 expose just opposite-- that really everything is a reference.

We use modify-by-reference in CGI::Application to prevent copying large HTML documents into the "postrun" routine.

This is a technique that should be used sparingly, as returning explicit values creates for clearer code flow.

Perl6 helps promotes good programming practices in two ways in this regard. 1. You have explicitly turn on modify-by-reference for a subroutine argument, and 2. This explicitness makes it clear that this trick is being employeed. Let's a take a look at the syntax:

  Was: sub foo {...};        foo(\$bar)
  Now: sub foo ($bar is rw); foo($bar)

Perl6 is /always/ passing references to subroutines in the background, they are just read-only by default. While in Perl5 you might have a dig around to see if modification by reference was happening in a subroutine, in Perl6 you can look no further than the signature.

If you want a copy of the value passed, Perl6 covers that too:

  sub foo ($bar is copy);

Aspects of this may seem formal compared to the looseness of Perl5. So far I've generally liked these changes, as compactness and clarity often come with them.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.