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

Re: Re^9: VarStructor 1.0

by Wassercrats (Initiate)
on May 13, 2004 at 04:44 UTC ( [id://353013]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Re^9: VarStructor 1.0
in thread VarStructor 1.0

Yes, it's open to criticism, but when that's ALL I get, I have to point out some of the script's worth.

...all the active variables are local to the current subroutine. Any longer-lived values live in a very very few globals...there are typically some global variables (my, but still treated as globally available) that control behavior of the rest of the program. I think this is healthy...

When I say global, I mean not "my". cgi.pm contains 15 globals, and I don't consider 15 to be "very very few."

I'll go out on a limb and say that a talented and experienced programmer would get the job done faster if he didn't use strict, assuming he learned that way or has an equal amount of experience both ways. Warnings would sometimes help and sometimes slow you down. Localized variables would sometimes prevent conflicts with imported variables, but aside from that, they're just novelties to me that pollute scripts with "my"s.

Replies are listed 'Best First'.
Re^11: VarStructor 1.0
by Jenda (Abbot) on Sep 02, 2004 at 12:37 UTC

    Considering the size of the module 15 is few. Besides there are resonable uses from globals and there are the unreasonable ones. In this case it's just some configuration variables, nothing that keeps changing and needs to be worried about.

    I'll go out on a limb and say that a talented and experienced programmer would get the job done faster if he didn't use strict, assuming he learned that way or has an equal amount of experience both ways.

    And here is where most of monks doesn't agree. At least if the task is something that will take more than 20 lines of code. But it's hard to give you a hard evidence since all talented and experienced programmers with equal experience both ways use strict whenever they can and only turn it off if they need to do something spicy.

    In some other node you said it's easy to devise a new variable name and scan the script to make sure it's really not being used yet. Isn't it even easier not to have to do that? And is not

    foreach my $line (something) {
    easier to write and read than
    foreach $lineIuseHereAndOnlyHere (something) {
    ? I use lexicals so I don't have to care whether there is another variable with the same name in a different part of the code. I use lexicals so I can take a piece of code and copy it somewhere without worrying that the two copies will overwrite each others stuff. I use lexicals.

    Jenda
    Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.
       -- Rick Osborne

      You said "...you said it's easy to devise a new variable name and scan the script to make sure it's really not being used yet. Isn't it even easier not to have to do that?"

      It depends on the situation. It's faster to do a search than to type "my" 50 times. Sometimes you could recognize that a variable has or hasn't been used before, and variables as long as your example of "$lineIuseHereAndOnlyHere" aren't necessary to make sure you know where belong and avoid accidental reuse, even in a 3000 line program. I know, because I wrote such a program.

      I'm not trying to talk anyone into using more globals. I just posted VarSructor, and if you have no use for it at the moment because you don't have to maintain a script that might have globals that you want to locate in the easiest way possible (seems like my detractors would be interested in that so they could refactor it), and if you don't have to reset variables in someone else's script so you could safely loop it without a major rewrite, then don't use the script.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://353013]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.