PackageDescription: Porting-NameSpaces


Porting - Name Spaces

Last published: April 16, 2010 by 'niallr'

Defines 1 Classes
Extends 3 Classes


In a single-namespace dialect, there is necessarily a single correct binding for each shortName reference in any valid code line-up. When we port a unit of code (i.e. an application or utility) from such a dialect to VW7, this remains true: there can be only one valid binding for all references to each name in the code. Porting is easier if the namespace to which we port exploits this.

For a name that has multiple bindings within its domain of visibility, a FirstFindNameSpace simply accepts the first binding it finds as the valid one for all code defined within it that references that name; it does not raise a DuplicateBindingError. Thus changing names in imported code can be avoided; just arrange the namespace' imports so that the port-preferred binding is the first one found for all duplicates.

The other binding(s) of a multiply-bound name can of course be accessed in such a namespace by writing their full name. However it will not raise duplicate binding errors when a short name of a duplicate is used, and duplicates will not show up in the launcher menupick 'Ambiguous References'. If you want to see them, convert it to its superclass via
MyFirstFindNameSpace changeClassTo: NameSpace
and re-invoke the menupick. The alternative to using a FirstFindNameSpace is to import specifically the desired resolution of conflicting items. FirstFindNameSpace can be a permanent solution or a temporary one for loading large amounts of code in which you then resolve conflicts by turnng each case into a specific import.

If you want to trial this behavior without changing the class of your namespace, just add the following extension to the package defining your namespace(s):

NameSpace>>conflictingImports: key firstFound: bind
"Do not raise a DuplicateBindingsError if my namespace sees two bindings but immediately proceed to what the defaultAction for the error would have been, namely to resolve the name to the first found binding. This saves us from having to add DuplicateBindingsError handling to every point where we would otherwise trap it, or else change short names to full names in ported code."

^self == MyPortNameSpace "or (... collection of my port namespaces ... includes: self)"
ifFalse: [super conflictingImports: key firstFound: bind]
ifTrue: [bind]

The works well and the only reason for not using it in general is that different people's usage would conflict (an example of the general OO rule that receivers are better than if-statements for determining behaviour choices).