Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
Hi Neighbor,

You write that the code you post is your first attempt at a Perl class. As a learning exercise, I think it's valuable to experiment with rolling (or stealing) your own. Perl has a minimal, to me elegant way to get object behavior.

If you'll be playing around a bit, you might like rewriting you class a few different ways. For my simple-minded application, Audio::Nama, I found Object::Tiny's accessors and class creation to be a good starting point. I filled out Alias++'s basic code with simple set() and dump() methods, spent a few days hacking together some YAML-based serialization routines and was on my way. I may change over to Mouse or Moose at some future time.

I found that a good environment to learn the types of compile and runtime errors I would get, how subclassing works, etc.

Regarding your code, first, redefining a subroutine is no big deal: if it's convenient to do so, do it and suppress the warning:  no warnings 'redefine'. It's your first class, after all.

Also you may like a more legible format for your default initializations:

package DataTable; sub new { my $class = shift; my $self = { tablename => undef, columns => [], indices => {}, datatypes => [], lengths => [], ... }; return bless $self, $class; }

All with a grain of salt and some monastery-brewed beer. When it comes to coding style, I am a youngster here.


In reply to Re: OO automatic accessor generation by gnosti
in thread OO automatic accessor generation by Neighbour

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others avoiding work at the Monastery: (5)
    As of 2014-12-20 09:00 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      Is guessing a good strategy for surviving in the IT business?





      Results (95 votes), past polls