Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Another thing I've noticed is that it's often fun to use complex structures, but possible (and even simpler) to use several simpler ones. Anyone else noticed this? How much time / effort have you expended creating a huge structure, only to realize that it makes much more sense to break it up?

Let's consider a hypothetical scenerio: I'm going to impliment a Geneology application in java. I'm going to have things like "Person" and "Place", and relationships like "child of" and "married to" and "born in". I decide to impliment this application, using new classes called "Person" and "Place". To handle the parent/child relationship, I'm going to have a getParentId() and getListOfChildIds() methods in my Person class, and you can use those Ids to look up the Object in a global hash table of all people -- which must constantly be kept up to date. This is kind of a pain in the ass, but I'm going to do it this way, because I don't want to have a lot of refrences. It's easier if all of my objects just store Ids, which I use as keys in simple global lookup tables.

Almost any java programer should realize this is ridiculous.

Perl is the same way. Regardless of wether or not you are useing true "blessed" objects, or just using hashes or arrays to represent your entities, using hashesrefrences to connect those entities together and show relationships makes a lot of sense. Is it easy to read code like thi? ...
$yak = $${$foo{'bar'}}{'baz'}[0]; but it's not much worse then this:
Integer yak = (foo->get("bar")->get("baz"))[0];

Which is why you don't write code like that if you want people to read it. Instead, you write code that derefrences things in to temporary variables with names that indcate what they are, and how they are used. And if that's stil not readable enough, you start to bless your hashes/arrays of nested refrences, and write some methods that treat them like objests so your code is even more readable.

Updated: stupid typo.

In reply to Re: Complex Data Structures by hossman
in thread Complex Data Structures by random

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, 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
  • 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.
  • Log In?

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

    How do I use this? | Other CB clients
    Other Users?
    Others musing on the Monastery: (8)
    As of 2021-03-04 15:47 GMT
    Find Nodes?
      Voting Booth?
      My favorite kind of desktop background is:

      Results (105 votes). Check out past polls.