in reply to How to initialize all variables

Never count on any language to initialize your variables for you. Just always initialize them yourself.

Replies are listed 'Best First'.
Re^2: How to initialize all variables
by eyepopslikeamosquito (Archbishop) on Sep 12, 2010 at 02:42 UTC

    I think you're being unreasonably insistent. Perl makes certain guarantees re initialization and I don't see a problem with relying on that. To my eye, explicit initialization often clutters more than it clarifies. For example, I prefer:

    my $fred; # $fred contains undef my @jock; # @jock is empty
    to the explicitly initialized:
    my $fred = undef; my @jock = ();
    Similarly, ANSI C guarantees that global/static variables are initialized to zero and I often take advantage of that by omitting explicit initialization, especially when initializing arrays (as I did, for example, in Re: Rosetta PGA-TRAM).

      I sure this will never happen to you or your code but what would happen if someone pass the code through a automate code translator ... say Perl 5 to Perl 6 or Fortran77 ... god knows. What would happen then? You don't know do you. It all depends on what the translator does, doesn't it? Or how the other language wants to initialize things. Since you did not implicitly initial your variables. I hope you remain blissfully unaware.

        what would happen if someone pass the code through a automate code translator ... say Perl 5 to Perl 6 or Fortran77 ... god knows. What would happen then?
        Given how much existing Perl 5 code relies on these initialization semantics, any Perl 5 translator that did not understand these semantics, and translate accordingly, would be pretty useless.

        Knowing the primary author of the upcoming official Perl 5 to Perl 6 translator, I doubt he'll have any difficulty with Perl 5's longstanding initialization semantics. :)

        There is no way to protect from buggy translators.

        Jenda
        Enoch was right!
        Enjoy the last years of Rome.