Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Introducing Class::InsideOut

by merlyn (Sage)
on Jan 09, 2006 at 17:16 UTC ( [id://522007]=note: print w/replies, xml ) Need Help??


in reply to Introducing Class::InsideOut

Congratulations on not duplicating the mistake that that both Object::InsideOut and Class::Std made in the documentation, namely:
package Foo::Bar; { ... }
Which should have been
{ package Foo::Bar; ... }
Too many people thinking of Perl6 already. Yes, I've reported it, but been ignored apparently.

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

Replies are listed 'Best First'.
Re^2: Introducing Class::InsideOut
by revdiablo (Prior) on Jan 09, 2006 at 20:40 UTC
    Yes, I've reported it, but been ignored apparently.

    FWIW, I've pointed out that same thing to the author of Object::InsideOut in Re: What is method () ?. His response there isn't entirely satisfactory, but it's perhaps better than no response at all.

      Likewise, I had an exchange on AnnoCPAN. I don't think it really hurts anything as long as the rationale for it is explained clearly and it's not copied blindly. Though, as my code attests, I don't favor the style, personally.

      -xdg

      Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Re^2: Introducing Class::InsideOut
by johnnywang (Priest) on Jan 09, 2006 at 21:13 UTC
    Can someone explain what this is about? the difference in syntax? and its relation to Perl6? Thanks.

      From my AnnoCPAN comment:

      These package blocks are only necessary if multiple classes are being defined in the same file, or there are mixed classes and code. (Which is what the synopsis shows.) They keep the lexical variables for each in separate scopes. If a single file holds only a single class, the enclosing file scope is sufficient and the braces aren't necessary.

      Perl 6 uses a class declaration with braces. From Apocalypse 12, here's an example of a Perl 6 class:

      # A Perl 6 class class Point { has $.x; has $.y is rw; method clear () { $.x = 0; $.y = 0; } }

      Since a Perl 5 package statement isn't exactly the same as a Perl 6 class statement, it's potentially confusing to write this:

      # A Perl 5 class package Point; { use Object::InsideOut; my @x :Field; my @y :Field('Accessor' => 'y'); sub clear { my $self = shift; $x[$$self] = 0; $y[$$self] = 0; } }

      In Perl 5, the braces are just defining a lexical scope, which inside-out objects happen to use to create encapsulation. But unless there are other lexical scopes in the file that defines the Perl 5 class, the braces aren't necessary and writing them on the same line may make people think it's related to the package statement. As an example, consider this version with the braces moved:

      # A Perl 5 class -- take 2 package Point; { # same guts as before } # still part of package Point outside the braces # but @x and @y can't be seen from out here

      Now consider what happens if the package statement is inside the braces instead:

      # A Perl 5 class -- take 3 package Foo; # just for later clarity { package Point; # same guts as before } # Back to package Foo out here

      -xdg

      Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Re^2: Introducing Class::InsideOut
by Anonymous Monk on Jan 09, 2006 at 21:20 UTC
    why, exactly, is that syntax a mistake?
      It's not a mistake. It's a preference. All three styles (package declaration outside the block, package declaration inside the block, and no block at all with file scope) work, and all have their own little pros and cons (none of which rise to the significance of such 'mistakes' as coding errors, syntax abuses or obfuscations).

      Unfortunately, such relative trivialities sometimes get overly exaggerated (even to the point of becoming flame wars); thereby distracting everyone from important topics such as xdg's excellent contribution to the Perl community which he has announced in this thread.


      Remember: There's always one more bug.
Re^2: Introducing Class::InsideOut
by Anonymous Monk on Jan 09, 2006 at 17:56 UTC
    Too many people thinking of Perl6 already. Yes, I've reported it, but been ignored apparently.

    That's 'cause you don't have enough XP. ;-)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2024-04-19 17:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found