Re: A Problem with v2.4 (for Rob)

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

On Wed, 14 May 2003 02:37:25 +0000, Al Getz <Xaxo at aol.com> wrote:

>
> Hello again Rob,
>
> While working with v2.4 i came upon a problem that has
> quite profound consequences.  The problem centers around
> the new implementation of 'include as'.
>
>
> --in file SomeoneElsesExistingFuncs.ew--------
> procedure DoSomething()
> ?{1}
> end procedure
> -- and 100 other procedures already named.
> ----------------------------------------------
>
> --in file MyNewFuncs.ew-----------------------
> procedure DoSomething()
> ?{2}
> end procedure
> -- and 99 other procedures, a lot with the same
> -- names as in SomeoneElsesExistingFuncs.ew
>
> ----------------------------------------------
>
> -- MyNewFuncs.ew DoSomething() does something slightly different
> -- then that which is in SomeoneElsesExistingFuncs.ew
>
>
> -- all the following in file Test.exw ...
>
> include SomeoneElsesExistingFuncs.ew
> include MyNewFuncs.ew as MF
>
>
> -------Someone elses existing .exw code section---------
> DoSomething()
> -- and call 100 other functions already named in
> -- SomeoneElsesExistingFuncs.ew
> ---------------------------------------------------
>
> -------My new code section (also in Text.exw)---------
> MF:DoSomething() --<----flags a name qualifier required error.
> -- and call 99 other functions already named in
> -- both MyNewFuncs.ew
> -------------------------------------------------------
>
> The interpreter flags a name qualifier required error because
> it doesnt see that "MF:DoSomething()" is different then simply 
> "DoSomething()".  This is exactly the same as Euphoria 2.2.

That is not quite what is happening. Euphoria sees "DoSomething()" so it 
looks for a local routine with this name. If it can't find one, it looks 
for a global routine with this name. In this case it finds two global 
routines with this name. Now, which one did you actually mean to use? How 
would Euphoria know? For example, if it assumes that because you didn't use 
the namespace qualifier that it should use the routine in a file that 
wasn't namespaced? Maybe, but that assumes you INTENDED to leave off the 
namespace qualifier. Rather than second guess you, Euphoria raises an error 
so that you can disambiguate the situation.

> This reduces the value of 'include as' in programming technique.
> You should be able to block completely the new code so as to
> provide perfect encapsulation without having to change
> var names.

You can - and using the current Euphoria.

> This means that either one of two things has to happen:
> 1. rename all the procedures in SomeoneElsesExistingFuncs.ew
> 2. rename all the procedures in MyNewFuncs.ew

Ah hah! There is a third alternative.
 3. Add a namespace qualifier on the "include SomeoneElsesExistingFuncs.ew"

Exmaple:
 include SomeoneElsesExistingFuncs.ew SE
 include MyNewFuncs.ew as MF


 -------Someone elses existing .exw code section---------
 -- Explicitly tell Eu that you want somebody else's routine.
 SE:DoSomething()
 -- and call 100 other functions already named in
 -- SomeoneElsesExistingFuncs.ew
 ---------------------------------------------------

 -------My new code section (also in Text.exw)---------
 -- Explicitly tell Eu that you want your routine.
 MF:DoSomething()


> Isnt this exactly the same as it was before v2.3 i think?
>
> If someone wants to include a file both without a name qualifier
> and with a name qualifier all they have to do is use the following
> code:
> include TheirFile.ew as TF
> include TheirFile.ew
>
> and that would acheive the same thing that exists now.

Which is nothing. A file only gets included once - no matter how many times 
you refer to it. In fact...

 include TheirFile.ew as TF
 include TheirFile.ew as YG
 include TheirFile.ew as UH

just creates namespace aliases for the same file. In other words ...

  TF:DoSomething()
  YG:DoSomething()
  UH:DoSomething()

all refer to exactly the same routine.

> This means if the interpreter is changed to stop recognition
> of globals in files that are exclusively included
> with 'include as' then this default action can be turned on
> or off by either using one line of code or two (as above).

I'm not sure what you are saying here. Are you saying ...

All globals defined in a file that has been included with the "as" phrase 
must ONLY be referred to by using the namespace qualifier - and thus if a 
symbol is not namespace-qualified in your code, Euphoria must not look in 
files that were included with a namespace qualifier

> This really has a big effect on what you can and cant write
> when it might be used with other peoples include files.
>
> Once this works it's going to be very useful.  The impact
> on the code that can be allowed will be incredible.

I agree that this would help your situation a lot. Maybe a warning might be 
useful in case the coder just forgot to qualify a reference or two. It 
would also potentially break existing code - but maybe not that much.

-- 

cheers,
Derek Parnell

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

Search



Quick Links

User menu

Not signed in.

Misc Menu