Re: Advice on converting archive files from 3.1.1 to 4.0
- Posted by mattlewis (admin) Mar 24, 2009
- 962 views
Namespaces
The problem seems to be namespaces ... and I understand the incompatible to arise for the following reasons:
Actually, I think most 3.1 code will work out of the box for 4.0.
Because of :
- the resolution of forward references in v4; and because
- included files don't have access to the namespace of the file which includes them (or any library files that the calling file has included);
it is necessary to specifically include each subfile which the library relies on at its start .. and so on down the line for each of the files which it includes.
(Perhaps this might be solved by a special version of include called include_compatible which resolves the namespaces in the previous way? )
Technically, it is only necessary if the symbols in the file are not global. 4.0 will still resolve global symbols in files not directly included. It's always been true that files don't have access to the namespace of any other file, since a namespace was treated as a local symbol in 3.1. A file still has access to symbols in the global scope of a file that included it. This should be considered bad practice, however.
With 4.0, the recommended practice is to use public or export scopes for your symbols in place of global, and to use include statements to specify the files containing the symbols your code will use. Simply doing this typically removes most namespace conflicts, as the parser can choose between symbols based on a clear expression of the programmer's intent.
One thing to look out for is mixing the 3.1 standard library with the 4.0 standard library. If you are using a library that uses the older library, but are using the newer one in your code, there is some help for that by using indirect_includes:
without indirect_includes include legacy_library.e -- rest of your code
The effect of this will be to keep the globals from the files included by legacy_library.e from clashing with your code.
Are there any other gotchas or elements that fundamentally change the way an existing v3 program is implemented in v4 that would cause it to break?
(sorry if this topic has been covered elsewhere but I haven't been able to find it in the forum)
There probably are. We had a wiki page listing some of these issues (can't find it now), and there's the start of something that introduces new things in 4.0.
Matt