in reply to to strict or not to strict

I use strict; all the time. But I started programming in C/C++, so not declaring variables at the beginning of my code is just weird to me. ;)

Replies are listed 'Best First'.
Re: Re: to strict or not to strict
by Jenda (Abbot) on Oct 16, 2003 at 21:48 UTC

    Declaring variables at the beginning of your code is only very slightly better than not declaring them at all.

    You should declare them just before you need them and only for the smallest possible block. IMHO of course.

    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

    Edit by castaway: Closed small tag in signature

      I do declare variables in the smallest scope possible -- but I do also put them at the beginning of the block. I find it's easier to organize, and I tend to think about my code more before I write it.

        I do declare variables in the smallest scope possible -- but I do also put them at the beginning of the block.

        Either you have a lot of very small blocks, or you're contradicting yourself.

        { my $foo; ... # n1 lines $foo = bar(); ... # n2 lines print $foo; }
        Scope of $foo: n1 + n2 + 3 lines
        { ... # n1 lines my $foo = bar(); ... # n2 lines print $foo; }
        Scope of $foo: n2 + 2 lines.

        Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }