Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I don't see how my use of globals is unsafe. If my use of eval could end up doing something dangerous because I'm improperly parsing the code before evaling it, please explain. I reviewed my code after you warned me about that, but I couldn't find a problem.
It's not necessarily that globals are unsafe. But they are bad. The reason they're bad is they create state. This is something that you'll appreciate even more if you ever program in a functional language.

When debugging, it is far easier to deal with code that doesn't use globals. Because the minute globals enter the equation, you can no longer be sure what's changing what. What looked like good input has been changed somewhere, leaving you dazed and confused.

And it may not hit you that bad. But the moment someone tries to take over your code and maintain it, they will get lost. By using lexicals, you can keep track of what's getting changed where. Every time you put in a set of values, you will get the same set of values back out.

There are exceptions to this rule too. Database handles are often a good example. They don't have state (mostly). Using a database handle in one subroutine won't cause another subroutine to have different output.

I'm pretty sure I've said this to you before, but: you should stop arguing and start asking. Chances are, there are reasons that things are the way they are. Sometimes they're bad reasons, like "because that's the way they've always been". And in that case, you can often feel free to change them. But many times there are good reasons. And you should try to figure out what they are before you say things are dumb.


In reply to Re^4: Wassercrats::Improved Volume 0, Number 0 by elusion
in thread Perl::Improved Volume 0, Number 0 by Wassercrats

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 perusing the Monastery: (3)
As of 2024-04-14 11:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found