Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
I have come to know about Devel::NYFTProf but not quite able to understand how to use it. The gui has a launching script which in turn calls some more scripts using some modules.

What do you not understand about how to use it?

You probably don't need to profile the gui itself, so how are you "calling" the other scripts from it?

Use faster accessors

The fastest accessor is the one you don't call.

It may go against OO-dogma; but in 95% of cases, there is no good reason to use subroutines to access instance variables from within that class's methods.

There are three main reasons formally cited for using accessors within a class's methods:

  1. To isolate the rest of that implementation from future substantial changes to the structure and/or layout of the instance data.

    This could only ever become a saving if that data layout changed beyond recognition; and if that happens, the likelihood that you would get away with not also substantially rewriting method code is almost nil.

  2. To provide centralised, single point validation of values assigned to instance variables.

    If your class is even vaguely well designed and written; it should not be possible for internally sourced assignments to instance variables to assign invalid values. Thus, re-validating those internally-sourced values for every assignment is pure overhead.

  3. People often respond to that with: "But what about values that come into a class from outside"?

    And the answer is that external inputs should be validated at the point of transition across the class boundary. Ie. Whenever an externally visible method is called; you should validate its parameters. But external code should never be directly accessing instance data, therefore there should be no such thing as externally visible accessors.

In short. External code calls methods to perform services, not access internal data. Where service methods accept arguments; those arguments must be validated immediately; and once so validated; any values derived from those arguments that subsequently gets set into instance variables require no further validation.

Thus, method code can safely directly access instance variables. Which in turn avoids both the overhead of accessor method calls; and centralised re-validation.

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
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.

In reply to Re: how to improve the performance of a perl program by BrowserUk
in thread how to improve the performance of a perl program by ghosh123

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 all is calm...

    How do I use this? | Other CB clients
    Other Users?
    Others meditating upon the Monastery: (3)
    As of 2018-01-21 02:00 GMT
    Find Nodes?
      Voting Booth?
      How did you see in the new year?

      Results (227 votes). Check out past polls.