in reply to strict, scope, my and foreach - not behaving as expected

I ran into some unexpected behaviour while adding 'use strict' to a working program.
I highly doubt that adding 'use strict' lead to unexpected behaviour. From the description of the problem, it looks to me that you added a 'my' that caused to problem you experienced. 'my' and 'strict' are two different things. You can use lexical variables without having any strictness enforced (just like you can drive the speed limit even without the police nearby!), and you can have strictness enforced without having any lexical variable in your program.

But what I really wanted to ask is Why? What's the point of adding 'use strict' to a working program? 'use strict' is a development tool. A useful one, but starting to use it on a working program adds, uhm, nothing. OTOH, it might prevent your program from compiling, inviting you to modify the program, which might cause all kinds of bugs to creep in.

Abigail

  • Comment on Re: strict, scope, my and foreach - not behaving as expected

Replies are listed 'Best First'.
Re^2: strict, scope, my and foreach - not behaving as expected
by wolv (Pilgrim) on Jun 09, 2004 at 13:18 UTC

    Modifying the program is not inherently harmful, and in my opinion, modifying code that does not run under strict is usually a good idea. Not that all programs should be made to run under strict, but the fact is that it prevents a lot of subtle bugs that might not come up in normal debugging at all.

    As to the problem in the original question, I'd like to ask 'why' too; why make the iteration variable global? Call-by-value is really not that expensive, and if you feel it is, use $_[0].

      Modifying the program is not inherently harmful,
      Not inherently harmful? I'd say a large percentage of bugs in programs comes from the fact someone modified the program. That's my point. If something is not broken, don't fix it.
      but the fact is that it prevents a lot of subtle bugs that might not come up in normal debugging at all.
      It was given that the program was working. I assume that the OP doesn't mean "it has bugs" when he writes "working".

      Adding strictness on a working program is a bit like rebuilding the Egyptian pyramids because originally the construction workers weren't wearing safety harnesses.

      Abigail

        The difference is no one is going to be adding on to the pyramids and even if they did the proper equipment could be used for the additional construction.

        New functionality may need to be added to the existing program, strict can help in that department but you would need it for the entire program. Plus just becase a program works doesn't mean it doesn't have bugs that could be caught by adding strict

        Everyone would be much better off if coders stopped writting code that "works" and instead started writting code that works well, scales, and is easy to maintain. Of course, since we are talking about humans, that's not too likely to happen soon :)