in reply to On Declaration

Well, declaration is to our $foo as "Array Of Hashes" is to [ { ... }, { ... }, { ... } ].

Neither may be accurate, but both terms are "close enough" that people have a pretty good idea what they mean when it iss said. Yes, the latter is really "Anonymous array containing a list of anonymous hashrefs", but only people like me (and apparently you) would ever be that pedantic. {grin}

-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.

Replies are listed 'Best First'.
Re: •Re: On Declaration
by sauoq (Abbot) on Jun 15, 2003 at 21:49 UTC
    Yes, the latter is really "Anonymous array containing a list of anonymous hashrefs", but only people like me (and apparently you) would ever be that pedantic.

    In the terminology I've always tried to use, that's a "reference to an anonymous array containing references to anonymous hashes." I don't see much wrong with calling it an "anonymous array"; that's a convenient shortcut. But where is the "anonymous hashref"? My understanding of the terms requires the referent¹ to be anonymous, not the reference.

    It seems to me that what people so often don't understand is that the value is what is anonymous. Using terminology like "anonymous hashref" just muddies the water, especially when used in the same breath as "anonymous array". You can't be truly pedantic without being consistent too.

    1. Of course, the referent could itself be a reference. If I saw my $r = \{ k => 'v' }; I'd say that the scalar variable $r holds a reference to an anonymous reference to an anonymous hash.

    -sauoq
    "My two cents aren't worth a dime.";
    

      "reference to an anonymous array containing references to anonymous hashes."

      In a sense the term "anonymous" is irrelevent when you are dealing with a reference to an object. From the point of view of a single statement dealing with a reference to an object every item so contained is anonymous. I would write the above as "a ref to an array of hash references.".


      ---
      demerphq

      <Elian> And I do take a kind of perverse pleasure in having an OO assembly language...
        In a sense the term "anonymous" is irrelevent when you are dealing with a reference to an object.

        In a practical sense maybe, but I think it draws a very important distinction. Even in practice, it is at least somewhat helpful¹.

        From an instructional perspective, I think it is useful to explain the difference between

        my $r1 = [ { foo => 'baz', bar => 'qux' } ];
        . . . and . . .
        my %h = ( foo => 'baz', bar => 'qux' ); my $r2 = [ \%h ];

        I think it is especially useful when you are speaking of an initialization and an anonymous composer because, at that point, you know all of the references to the anonymous data are accounted for. Even in the general case though, saying out loud, "a reference to an anonymous array containing a reference to an anonymous hash" is giving more information than saying "a reference to an anonymous array containing a reference to a hash." The latter makes me want to ask, "which hash?"

        Fixed: Missing closing brace in first bit o' code. Thanks zby.

        Fixed: Yes, I meant %h. Thanks demerphq.

        -sauoq
        "My two cents aren't worth a dime.";
        
Re: &bull;Re: On Declaration
by demerphq (Chancellor) on Jun 15, 2003 at 13:37 UTC

    Indeed I would get that pedantic. :-) Although I would say that IMO the fudge involved in Array of Hashes or even the even worse List Of Lists or List of Hashes is far more palatteable than the fudge involved in calling our a declaration. The problem to me is that the "standard" english usage is quite different from the usage in computing. In english we consider a declaration to be a statement of fact or a statement of an assertion, or an intention. In computing we usually mean the declaration of the existance of a particular object, and the name to which we shall call it. This is a pretty serious additional meaning, and I've seen a lot of newbies stumble over the distinction.

    I realize you have a lot more experience than I do teaching perl, but I wonder if you think about it how often you've had students say "Ok so 'my' creates a lexical variable and 'our' creates a global variable?" Umm no. "So strict catches usage of nonexistant variables?" Umm no. You see what i mean?

    Wheras the AoH LoL etc, is a much simpler and easy to explain distinction. Especially when you have Data::Dumper to easily show them the difference/sameness in a visual way. Although I do feel that it is far too easy to blur the concept of the container and the contents of the container in perl. But again I dont think these conceptual problem are much of anything unless you start hacking internals or doing funky mojo.


    ---
    demerphq

    <Elian> And I do take a kind of perverse pleasure in having an OO assembly language...
      But again I dont think these conceptual problem are much of anything unless you start hacking internals or doing funky mojo.
      Well, one very practical outcome of keeping terminology correct about "Array of Hashes" vs "Arrayref of Hashrefs" is that the word "ref" there implies a dereferencing must happen, and that indeed is visible, and important.

      -- Randal L. Schwartz, Perl hacker
      Be sure to read my standard disclaimer if this is a reply.

        True enough. I more meant the mental tangle that you can get in if you think of a reference to an array as being the same as the scalar that holds the reference. On face value its an obvious distinction, but I think people often get confused when scalars and scalar references get involved. For instance (and I know you know this one) how many variables are there in the following code

        my ($x,$y); $x=\$y; $y=\$x; my $aref=[$x,$y];

        Anyway. :-)


        ---
        demerphq

        <Elian> And I do take a kind of perverse pleasure in having an OO assembly language...