Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Tutorial RFC: Guide to Perl references, Part 1

by sundialsvc4 (Abbot)
on Jul 08, 2015 at 19:37 UTC ( [id://1133783]=note: print w/replies, xml ) Need Help??


in reply to Tutorial RFC: Guide to Perl references, Part 1

Two things that I would include in any tutorial on references, and in early installments:

(1) Reference Counting:   Perl allocates bits of storage for many purposes (including the storing of variables and their values), cleaning them up automatically when they’re no longer being referred-to.   It counts the number of references that currently exist, including both the ones that you create (explicitly), and the ones that it does (implicitly).   (You don’t need to wander off into a discussion of “weak(ened) references.”)

(2) EQUIVALENCE:   This FORTRAN term might be unknown by now, but it let you say that two variables occupied exactly the same area of storage.   References effectively do the same thing:   if two references exist to the same bit of storage, well, they both refer to one and the same bit of storage!   The Perl language makes it very easy to use references in many powerful ways if you know what you are doing ... and to construct statements (especially, those involving references) which do not actually do or say what you think they do.   In your testing, you need to be sure, both that equivalent-references exist when you think they do, and that values are actually distinct when you expect them to be.

And here’s the specific reason for these two suggestions:

(1) If you refer to references as “a pointer to ...” when you are speaking to a programmer who is accustomed to a non-interpreted frame of reference (or, for that matter, even Java), one of two “mental de-railings” might occur.   The “C/C++” bare-metal programmer might not be familiar with this kind of storage-allocation strategy.   Users of other also-interpreted language systems which do not expressly provide for references might also become confused.   (And, in an educational effort like this, “if you lose ’em, they’re gone.”)

(2) Most of the really-nasty bugs that I have ever had to chase down in (always, someone else’s ...) Perl programs ... have had something to do with precisely this problem.   And, it has certainly “cut both ways.”   Either the programmer meant for the storage to be distinct, or s/he intended for the references to be equivalent.   “Perl compiled the source-code, nonetheless” (even with use strict/warnings), but it did not do what the original-programmer thought it would.

It’s a delicate balance, of course, as to when and where you want to choose to “refer to the smelly-fish” in an education topic that is basically targeted at newbies.   I generally think that suggestions should be dropped early, so that you can circle-the-wagons to them later on.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1133783]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2024-04-23 22:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found