in reply to Re: Weird Warning
in thread Weird Warning

Please do not do this.... This is akin to turning up the radio so you don't hear the nasty sounds your engine is making. The warning is there because you are likely missing a condition that you did not think of, turning off warnings only removes the message not the problem it is warning you about.

Replies are listed 'Best First'.
Re: Re: Re: Weird Warning
by Aighearach (Initiate) on Jun 25, 2001 at 21:55 UTC
    warnings are a good thing. I'd never just turn them off to begin with. But saying that an experienced programmer is likely missing something because there is a warning is rather suspect. The argument works great for the general case, because at the level of a whole program there is a lot more room to miss something. But, if there is a reason not to turn off specific warnings for a short time, it isn't that there is still a "problem." For example, if you'll dealing with hashes, you'll get uninitialized errors in some types of things, but whether it's initialized might be besides the point. If it exists might really be what matters.

    Adding extra code that isn't needed to get rid of the warning is at least as bad as turning off the warning where you know it isn't a problem, so judgement is required.

    I think a good rule is, "if you fully understand why you're getting the warning, then it's your call if it should be on or off." If you don't know what the warning is, but just want it to shut up, then yeah, read the manual, fix the code, etc.
    --
    Snazzy tagline here

      I respectfully disagree...

      Just because you "know" why, and don't feel like updating your conditionals, etc -- imagine 3 months or more down the line someone else has to support the code. They will not "know" the same thing you do.

      The more complete, easier to maintain method (IMO) is to update your conditionals...

      if ($foo{'test'} eq 'bar') { } # Becomes # exists could be defined depending on circumstances. if ( (exists $foo{'test'}) && ($foo{'test'} eq 'bar') ) { }
      This code now makes it explicit to future maintainers that there is a possibility that the code could be querying non-existent data, and that this is an expected behavior (expected because the code supports it).

      I would personally rather see the conditionals, etc updated rather than seeing warnings being flipped on and off throughout the code.

      Plus, the questioner was obviously new to using hashes and was making a mistake with their use of them. So your answer to turn off the warnings would have resulted in the hiding of an error, the error that you "knew" was not there and "fully understood" the reason for.