Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

I don't understand why you didn't go the easy way of defining my %rtoa either on file or function scope.
Though that was easier, I am pedantic and just couldn't bring myself to do it:
  1. I didn't want %rtoa at file scope because other functions in the same file have no business knowing about its existence - it is a roman_to_dec() implementation detail after all and I should be able to later change the implementation of this function with complete confidence that doing so cannot possibly break other functions in the same file ... which is why I originally created the bare block, solely to hide %rtoa from other functions in the same file.
  2. I didn't want my %rtoa at function scope because it is gratuitously inefficient to (unnecessarily) initialise %rtoa each and every time the function is called (it is a constant after all). More importantly, expressing that %rtoa is const and is used only by roman_to_dec aids code clarity (BTW, I miss C++'s const keyword when coding in Perl).
BTW, it seems to me that state variables were added to perl expressly to solve the above two concerns.

Update: Re the rationale for introducing state variables, found a quote from Larry himself in Re: About "state" variables in Perl 5.10:

However, that difference is not why we introduced state variables. The big win is the psychological one of not having to look outside of the sub to find the definition of $x. (That, and we wanted it as a primitive in Perl 6 so that people could write stateful macro constructs without forcing the user to define the state variable externally; in fact, we also use it ourselves in order to implement the stateful flipflop operator without having to build the flipflop in as a primitive, as it is in Perl 5.)


In reply to Re^9: A short whishlist of Perl5 improvements leaping to Perl7 by eyepopslikeamosquito
in thread A short whishlist of Perl5 improvements leaping to Perl7 by rsFalse

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (2)
As of 2024-04-16 21:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found