Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: To initialise or not to initialise?

by dragonchild (Archbishop)
on Jun 24, 2004 at 12:30 UTC ( #369316=note: print w/replies, xml ) Need Help??


in reply to To initialise or not to initialise?

. . . after reading about variables being set to old values under mod_perl . . .

Do you even know why this happens? Do you know if this happens outside mod_perl? Has this been an issue for you in programs you've written?

In other words, if it ain't a problem, don't fix it!

Oh - and I don't have global variables. Just having them is a sign of logical weakness, initialized or not.

------
We are the carpenters and bricklayers of the Information Age.

Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

I shouldn't have to say this, but any code, unless otherwise stated, is untested

  • Comment on Re: To initialise or not to initialise?

Replies are listed 'Best First'.
Re^2: To initialise or not to initialise?
by kiat (Vicar) on Jun 24, 2004 at 12:50 UTC
    Hi dragonchild,

    Do you even know why this happens? Do you know if this happens outside mod_perl? Has this been an issue for you in programs you've written?
    A little quote from my original post...
    if it might be better in general to initialise each and every variable. So, instead of the above, we now have:
    I used the words in general so I wasn't looking at any particular situation.

    It is not an issue to me, but nonetheless I was interested to hear from the experts here what the normal practice is.

    One of Perl's uniqueness is "there's more than one way to do it". I was curious to find out if there's indeed a preferred way of treating variables wrt value initialisation.

Re^2: To initialise or not to initialise?
by skyknight (Hermit) on Jun 24, 2004 at 14:35 UTC
    Oh - and I don't have global variables. Just having them is a sign of logical weakness, initialized or not.

    Eh, we should be careful how we define "globals" when making such statements. Indeed in strictly procedural programs it is foolish and unnecessary to have global variables. However, what about package globals? Having in Perl what would be denoted in other languages as a "static class member" is not an unreasonable thing to do, and is often in my experience necessary.

      Those aren't globals. Those are static class members. That they are implemented as a package global is completely and utterly irrelevant. The same goes for any other CS construct you can think of that in Perl is implemented as a package- or file-scoped global. Truly global variables are good for three things only:
      1. Hacking a one-off
      2. Prototyping
      3. Demonstrating how p00r yur skillz R

      ------
      We are the carpenters and bricklayers of the Information Age.

      Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

      I shouldn't have to say this, but any code, unless otherwise stated, is untested

        Well clearly we are in fundamental agreement. At this point we are just arguing linguistic semantics.
Re^2: To initialise or not to initialise?
by DaWolf (Curate) on Jun 24, 2004 at 21:18 UTC
    In other words, if it ain't a problem, don't fix it!

    A very dangerous statement, IMHO. It may be not a problem *YET*, but can turn into a problem later. I agree with you that he should know why the problem happens, but even if he can't he should correct it.

    This way he can produce a more "secure", "risk-free" code.

    Just my 2 cents.

    Regards,

    my ($author_nickname, $author_email) = ("DaWolf","erabbott\@terra.com.br") if ($author_name eq "Er Galvão Abbott");

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2021-10-24 16:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (89 votes). Check out past polls.

    Notices?