Technically speaking, a package is a named collection of related parts, but it can be easier to think of a package in the same way as a folder or directory on your local system.
Packages prevent name conflicts by separating files into different contexts. Two parts with the same name cannot be defined in the same package, but two different packages can each have a part with the same name. Likewise, you should prevent conflicts between packages by not creating packages with the same name, even if those packages are in different projects or source folders.
The parts in an EGL source file all belong to the same package. The package statement in the file, if any, specifies the name of that package. If you do not specify a package statement, the parts are stored in the root of the source folder and are considered to be in the default package. Because files in the default package cannot be shared by parts in other packages or projects, it is best to specify a package statement.
Package names are case sensitive. For more information on naming conventions for packages, see package.
package com.companyb.firstpackage;
program testProgram type BasicProgram
function main()
myVariable myRecordPart;
end
end
Record myRecordPart type BasicRecord
field1 int;
field2 string;
end
package com.companyb.secondpackage;
program testProgram2 type BasicProgram
function main()
myVariable2 com.companyb.firstpackage.myRecordPart;
end
end
As shorthand, you can use the import statement to tell EGL that you want to use the part in the source file. If you import a part in this way, you can use the part as though it were in the current package, without specifying the complete location of the part within its package each time you use it. Sometimes, importing a part in this way is called "bringing the part into scope."
package com.companyb.thirdpackage;
import com.companyb.firstpackage.myRecordPart;
program testProgram3 type BasicProgram
function main()
myVariable3 myRecordPart;
end
end
Note that the import statement
uses
the package path to the part and the part name, not the source file
name.For more information on import, see Import and use statements.