On the subject of heresy, I'd like to add a few remarks:

Your 'method' proposal is something that I tried to implement using existing technology, but could only come up with something that looked a sight more awful:
method 'somemethod', sub { # ... }
This wasn't as syntactically sexy as I had been hoping for, due to the fact that you can't pass named subs to a function like you can pass anonymous ones.

Further reflection on this problem, though, made me realize that one way to insert this functionality into the language without major syntactic complications is to define a 'package' like operator called 'class' which operates differently.
class Thing; our ($property,$size); sub new { return $self; # Returns a handle to this object } sub Implode { $size = 0; # Local to this object instance }
Any 'sub' within a 'class' declaration will always have a variable '$self' defined. If the sub is called bare, as in:     my ($thing) = new Thing(); If no existing variable is referenced, then a new $self is created, and is populated with any 'our' declarations from the module. This avoids the problem that plagues 'OO' programs now where an object sub may be called with no object, meaning that the first item in the stack is not actually $self, but the first parameter, forcing you to check that the first param is actually an object.

On the other hand, if the function was called with reference to a specific object, such as:     $thing->Implode(); Then $self will have the value of $thing, and the namespace will be switched to be local for that object instance, such that any changes to things like '$size' will not bleed into other instances.

In reply to Re: Heresy by tadman
in thread Heresy by thayer

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.