in reply to Use of uninitialized value

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re^2: Use of uninitialized value
by blazar (Canon) on Mar 01, 2007 at 10:49 UTC
    but haven't found any problems jet with additionaly using the pragma:
    no warnings 'uninitialized';

    Indeed it is the single warning that one most often wants to disable, but locally, when he knows what he's doing, for otherwise even that is useful to catch situations in which an undefined value does slip in, that shouldn't. Certainly it has helped me to catch a logic bug, in a few occasions.

Re^2: Use of uninitialized value
by Old_Gray_Bear (Bishop) on Mar 01, 2007 at 19:02 UTC
    lostsoul said:

    but haven't found any problems jet with additionaly using the pragma:
    no warnings 'uninitialized';

    Perhaps I am being a bit too old fashioned and conservative here; but If I saw that in a code review, I'd issue an immediate "Reject -- Unsafe Coding Practice; Not Allowed In Production" defect and terminate the review right then and there.

    The 'initialized variable' warning is an indicator to me that the Coder either: a) doesn't understand the logic because He (and almost all ways it's a male) couldn't figure out what the proper starting value should be, or b) is too lazy to add the three or four more characters needed to ensure that the subsequent code has a sound starting place. Turning any warning off is an immediate red-flag.

    This is another example of "Just because you CAN do something doesn't mean that you SHOULD do it." In the forty plus years I have been playing at this Game, I have been bitten by the initialized-variable problem far too often; I can't think of one occasion when I couldn't define the proper starting conditions for my variables.

    Note: I started my career on machines that did not 'zero-core' before loading a new program. If you didn't initialize your variables, they started with what ever bit-trash was lying in the patch of memory they were assigned. I spent the entire summer in my Junior year debugging a C compiler that Bell Labs had "ported" to the S/360 (an IBM mainframe Operating System), because of the tacit assumption that all numerical variables (either init, float, or double) would contain x'00' as their initial value. I come by my bias honestly. And yes, I finally ran down all of the for loops (both the explicit ones and all the implicit loops); but it took three long months of debugging some 'really clever code' in a language that I had only just been exposed to. ("Hey, weren't you read K&R just last month? Here is the problem we have and you're just the lad to sort it out.")

    ----
    I Go Back to Sleep, Now.

    OGB

      I did have my concerns when starting to use it but the occasions where it really gets in the way of toubleshooting are very sparse. And I like to use undef as a valid value in many situations - so my initial value often is undef.