current stable: 0.99.6 unstable: cvs (0.99.7) |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
NamespacesNamespaces are defined in the following manner:
All languages have namespaces, Java's are governed by static members to classes but C has no means of explicitly defining them. The are a means of grouping likewise data and functions into a group such that there doesn't exist conflicts with names (hence namespace). Functions, Variables, Classes and even other namespaces can be defined within a namespace. Example: A standard error message for two different systems within the same program - Text and Graphical. In C it would have to be done like so:
Whereas in ferite you would use namespaces:
The ferite method is cleaner as it is more obvious what belongs to what, and also allows the programmer using the Graphical and the Text API's to know that if they want to show an error message they merely call the printErrorMessage() function in which ever namespace they want. If you combine this with the ability to assign a namespace reference to a void variable - very powerfull abilities become apparent. Using the above code:
They promote clean and precise code. When a function is defined within a namespace it has to reference stuff within the namespace as code out side does, e.g. namespace.resource. It is important to note that you can't use the shortcut method to access functions and variables that is used in objects e.g. .someVariable. You must use the full name to access anything within namespaces. Modifying Existing NamespacesThere is also an alternative syntax for namespaces allowing you to extend an already existing namespace or create a new one if it doesn't already exist. This is done like so:
When this modifies the namespace it places all items within it in the block in the namespace mentioned. Eg:
In the above example the namespace foo has a number i and a number j. The main reason for this syntax was to allow module writers to easily intermingle native and script code within the namespace. There is also times when placing something in another namespace makes more sense. e.g. Placing a custom written network protocol within a Network namespace. It is possible to use the same delete and rename functions as in classes, in namespaces.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||
ferite et al © 2000-2004, Chris Ross |