Re: scope of variables

new topic     » goto parent     » topic index » view thread      » older message » newer message
DerekParnell said...
coconut said...

Why do you want to change a rule that is accepted in all languages: >>One can redeclare a variable inside a function and shadow an outer one.<<

BTW, how does one refer to the encompassing var that has been shadowed in other languages?

In the languages that allow it (not all, and not common) you don't. You're cut off from it. There may be an obscure langauge out there that allows parent access, but I don't know of it. Any one else?

I'll research this topic in a bit with some other common languages. I'm not closed to the idea of causing a variable to shadow another, I just think it's a bad language design, bad coding design and has not a single thing going for it. One mentioned not being able to remember a previously defined variable and accidentially creating the same variable name after a few months. That's a pretty poor reason I think. At first run of your program, it will immediately say "Cannot redeclare variable..." and then you'll remember. Thus, we are still down to no valid reasons.

When working with PHP, the only thing I have found when this type of functionality exists is bugs that are hard to track down and it's not a bug here or there. It's a very common bug. Why do we want to open Euphoria up to this possibility w/zero benefit? Some may say "look at goto..." #1. Goto has valid uses and #2. Goto cannot be accidentally used and cause bugs. I could easily (as anyone) accidentally reuse a variable, then a month later see the top level variable and in side of a function begin working and wonder why my top level is not being changed.

If we decide to go this method, at bare minimum a stark warning that is on by default needs to be issued if a variable gets shadowed. This is a poor comprimise because in the end the warning will just make everyone code the right way as an error would have or it will cause all sorts of eu.cfg files to start having warning flags disabled and then one person deploying code thinking all is OK, and another (with out ignoring warnings) complaining the code is buggy. Over all, a poor decision for Euphoria users all around: Let's change the language to allow buggy code for no reason. We might as well insert random gotos in the IL smile Ok, a bit extreme but not too far smile

Jeremy

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu