Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

RFC: pragma 'use dev;'

by rvosa (Curate)
on Aug 25, 2006 at 21:52 UTC ( #569744=perlmeditation: print w/replies, xml ) Need Help??

dev - pragma for development code

A simple idea: a single pragma to switch between development and production code behaviour.

Synopsis

use dev; # turns on strict, warnings, diagnostics use dev 'LOGLEVEL' => 1; # turns on logging preset use dev 'WARNFATAL' => 1; # warnings cause death use dev 'ONFATAL' => sub { ... }; # callbacks no dev; # for stable production code

Rationale

Using dev would make it simpler to turn on and off things you might want in development code, but not in production code. Also, it might encourage standardization on certain logging tools and exception handling mechanisms.

Replies are listed 'Best First'.
Re: RFC: pragma 'use dev;'
by Tanktalus (Canon) on Aug 25, 2006 at 23:49 UTC

    To be honest, I'm not facing a bunch of situations where I particularly want to avoid strict, warnings, etc. Or, rather, I want them to be worked out before production because if they happen in production and they're masked, I may never know that my data got silently munged.

    As for the logging, warn-fatal, etc., I probably want most of those either in a logfile or in my commandlines (or both).

    I standardised our logging tools and exception handling mechanisms by centralising them in a Log module. Admittedly, it isn't a great mechanism, but it does suffice for our purpose. And it's the same code for all our scripts. I also standardised a lot of other things by putting them in modules. Such as commandline handling.

    I'm not saying your idea isn't good. I'm saying that if it is, I'm currently missing it.

Re: RFC: pragma 'use dev;'
by derby (Abbot) on Aug 26, 2006 at 11:44 UTC

    It's an interesting idea but I would want it to key off ENV vars. That way as I move code from a dev to a test to a production environment, no changes need to be made to the code.

    -derby
Re: RFC: pragma 'use dev;'
by adrianh (Chancellor) on Aug 26, 2006 at 16:25 UTC
    A simple idea: a single pragma to switch between development and production code behaviour.

    You seem to be saying that switching off logging, strict and warnings in production code would be a good idea?

    I find that a curious suggestion - since I'd want them there more than anywhere else.

      Thank you all for your comments. I think I should clarify that I probably didn't mean that none of strict, warnings, logging etc. should be used in production. But I do think that many people have different configurations for dev versus production.

      I can only really speak for myself, so in my case, in production, I use strict, but no warnings or diagnostics (e.g. in libraries). I set logging (Log::Log4perl) to 'warn' rather than 'info' or 'debug'. For cgi programming, I like to have fatals go to the browser when debugging, but not when the site is in production. The idea was that you could switch easily between such different configurations.

      I like the suggestion of using environment variables to specify what these configurations are, thanks.
Re: RFC: pragma 'use dev;'
by diotalevi (Canon) on Dec 11, 2006 at 19:57 UTC

    Here's your entire module:

    package dev; use pragma -base; 1;

    ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

        Ok? Post something at AnnoCPAN where I'm not being clear or help me out somehow. Just saying "that's cryptic" isn't helpful to me.

        ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

Re: RFC: pragma 'use dev;'
by ysth (Canon) on Dec 12, 2006 at 06:02 UTC
    Don't forget QA, which may want some dev "features" but not others.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2020-11-26 02:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?