Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

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

by chromatic (Archbishop)
on Sep 29, 2010 at 15:05 UTC ( #862623=note: print w/ replies, xml ) Need Help??


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?
Re^2: At what level of structural complexity is Moose a win-win?
by Corion (Pope) 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 (Pope) 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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://862623]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2014-12-26 02:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

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





    Results (164 votes), past polls