http://www.perlmonks.org?node_id=862623


in reply to At what level of structural complexity is Moose a win-win?

The question I ask is "Is this data structure clearer as an object?" For a simple stack, the answer is often no. For a value such as currency—even if the only attributes of the object are two integers to represent dollars and cents—the answer is often yes. Remember that associating a distinct identity with a data structure adds clarity and helps reduce bugs.

  • Comment on Re: At what level of structural complexity is Moose a win-win?

Replies are listed 'Best First'.
Re^2: At what level of structural complexity is Moose a win-win?
by Corion (Patriarch) on Sep 29, 2010 at 15:22 UTC

    Why would you want to store currency as two items, instead of storing it as an amount of cents alone?

    What makes more sense in this context is to store a monetary amount as the currency it is in, together with the amount and potentially the place of the decimal point.

      Sure, that's usually a better approach. I don't remember the details of why, but for one project it made sense to store dollars and cents separately. (Maybe it was because the retailer used the number of cents to indicate special information such as "manufacturer price" and "clearance price" and we didn't want to recalculate from decimal information every time.) Pre-breakfast, of course that was the first example to come to mind.

Re^2: At what level of structural complexity is Moose a win-win?
by BrowserUk (Patriarch) on Sep 29, 2010 at 16:09 UTC
    Remember that associating a distinct identity with a data structure adds clarity and helps reduce bugs.

    Using an object:

    use Currency; my $amt = new Currency;

    And not:

    my $amt = [0,0];

    And two screens down in the code:

    my $oldAmt = $amt;

    But which file are you in?


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.