While using inheritance with "classic" blessed hashref-based objects, is it generally recommended to name instance variables (the hash keys) using the current class name, say, like $self->{ThisClass__foo}, rather than $self->{foo}?

I read somewhere (can't recall where) that it helps safeguard you from accidentally writing over your parent class's instance variables, and it makes sense (though is admittedly also a bit clumsy).

I tried it out, and it actually helped expose where I'd previously accidentally accessed a parent's instance variable directly. Being familiar with the internals of the parent class (or classes) seems to make this kind of error easy to commit.

(I realize the problem can be avoided altogether using more modern OO techniques (like inside-out objects (or Moose, I suppose)).)


In reply to classic OO Perl: naming instance variables by j3

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.