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

Re: Re: Debug code out of production systems

by liz (Monsignor)
on Jan 25, 2004 at 10:51 UTC ( #323958=note: print w/ replies, xml ) Need Help??


in reply to Re: Debug code out of production systems
in thread Debug code out of production systems

If I understand correctly, this optimization is done by the optimizer, working on already compiled code. This has a number of drawbacks:

  • The code must be compilable
  • Effort is spent compiling, that is thrown away later
  • Any BEGIN type code in there will have executed, so if you have a use in there, that module _will_ have been loaded.
To prove that last point:
if (0) { use strict; } print "INC = @{[keys %INC]}\n"; __END__ INC = strict.pm

Furthermore, to activate sections of code, no changes would need to be made to the program. It's all external with my solution. With your solution, you would have to export constant subs to all namespaces, a not so easy task and a definite pollution of namespace. Even though the optimizer takes away sections of code, there remains a coderef to the original constant in the package namespace. See this example:

sub FALSE () { 0 } if (FALSE) { use strict; } print "INC = @{[keys %INC]}\n"; print "FALSE exists\n" if exists &FALSE; __END__ INC = strict.pm FALSE exists

Hope this explains some of the reasons I had for doing it the way I did.

Liz


Comment on Re: Re: Debug code out of production systems
Select or Download Code
Re: Debug code out of production systems
by Abigail-II (Bishop) on Jan 26, 2004 at 00:55 UTC
    Effort is spent compiling, that is thrown away later
    Which is done in C. A source filter spents effort filtering - doing the work in Perl. Do you have any figures that show you have some form of "gain"?
    Any BEGIN type code in there will have executed, so if you have a use in there, that module _will_ have been loaded.
    Depends on how you write it.
    use if 0, My::Module;
    will not load My::Module.

    Abigail

      Do you have any figures that show you have some form of "gain"?

      No. I don't think there will be any chance of a gain until I rewrite the main conversion logic in XS. But I'm not in it for the gain of execution speed. I'm in it for the gain in the development cycle of a program.

      use if 0, My::Module

      Of course. But in that case I would prefer the idiom:

      if (CONSTANTTOBEFALSE) { require My::Module; }
      or, if execution of the import routine is necessary:
      if (CONSTANTTOBEFALSE) { require My::Module; My::Module->import; }

      I think that is much more descriptive of what is going on than the use of the if pragma.

      Liz

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2014-12-20 22:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (99 votes), past polls