Re: problems with the scoping in eu4

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

To summarise, clarify and re-emphasise points:

I am not particularly concerned about syntax. I am concerned about meaning.

1 Inability to reuse for-loop variables:

The issue here is that using i,j,k for loop indices is common practice. It's universal mathematical use just as a,b,c are constants and x,y,z are variables./
The problem in Euphoria is that when the variable has gone out of scope the name and it's type hasn't. That says to me broken scope.
This is emphasised when we see that function parameters do shadowing correctly. The parameter can be of any type and it eclipses the outer declaration only while it is in scope.

2 While loops:

This isn't about static variables. It is about continued re-declaration.
The issue of reusing variables should imply that it is illegal to create variables in a loop as the name will not be released after use.

To say that the variable doesn't persist from loop to loop (Matt) is wrong - the variable should not go out of scope until the loop is exited. Therefore either the variable creates a re-declaration error as in 1 or the the declaration line has to be skipped on subsequent loops.

Initialisation to a constant should be possible if variables can be created in a loop.

One *could* enclose the declaration in an if-test but that is very defensive and is an avoidance of the issue

What should happen is that the the declaration is treated as part of the initialisation of the loop.

3. While with entry:

Starting at the bottom of a loop to avoid initialisation problems is bad design. Performing a sequence of statements out of order is *unstructured*. In the context of variable declaration it is a *jump into scope*.
It will break things.
And it is picked up by the compiler.

Starting at the bottom could mean starting 200+ lines away from the head of the loop (really bad stuff - but possible).

Nesting such loops makes for a kind of spaghetti. Stick a large switch in it and you have a complete mess.

Many may have voted for while with entry as a cute idea based on a single loop which could have been coded as a loop .. exit on condition ... end loop structure. I don't think they were voting for its use with variable declaration, nesting etc.

4. Switch:

No one seems to have commented on this.

Switches tend to be long as they enumerate the values the switch variable can take.

Declaring variables in a switch means they will be in scope over a large piece of terrain and multiple case labels. Jumping into scope will certainly happen. Fall through will allow other ways of coming into scope.

If variable declaration is outlawed in switch it would be no loss. However it raises an issue which is what to do if you want a local variable in a switch.

5 Blocks:

In order to limit the scope of variables it is necessary to be able to declare block scope. Currently that means: use a do once loop, or an if true then .. end if block or a procedure.

A block is conceptually very simple.
Example: in-line swap:
assuming two integers x, y
begin
integer t = x
x = y
y = t
end


If you like it is C's { .. } only {} means sequence.

If there were some expensive procedure to be done a block allows the space to be reclaimed immediately the block is complete.

Clearly blocks like this make more sense than declaring in loops or switches unless loop wide, switch wide scope was needed.

Having its own notation is cleaner than perverting loops or conditionals to this use.

Conclusion:

But first scope needs to be fixed.

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

Search



Quick Links

User menu

Not signed in.

Misc Menu