I can see two positions:
1.) don´t add new keywords to the main namespace, put everything new into an include file into it´s own namespace in order not to enlarge and "pollute" the main namespace.
2.) add new keywords to the main namespace, because having to use the namespace prefix all the time, is laborious and makes the code look ugly.
- position 1 requires including the include file + "using <namespace>" (which will become complicated, if you need several additions having their own namespaces), or using the namespace as a prefix all the time
- position 2 means extending the main namespace in an unacceptable way in the long run.
Maybe i can offer a compromise, which requires adding only one (or very few) new keywords to the main namespace for a whole bunch of new (related) features.
For example the array features i wrote (could basically be applied to other features too):
Everything is inside an include file, so as long as this file isn´t included, nothing is added to the main namespace. By including it one main macro ("array") is added to main namespace. Everything else is in a namespace ("array_") or prefixed with "array_" or "ax_" + <very unusual name>. As a result what´s exposed to the user offers a nice and clear syntax without the need for "using <namespace>" or using the namespace prefix.
A typical use of it would be:
array(sort, <additional parameters>)
array(insert, <additional parameters>)
array(delete, <additional parameters>)
result = array(scan, <additional parameters>)
The first word after "array" specifies, what to do with an array. The list of words (sort, insert, delete, scan) could be expand at will. These words can be used everywhere else in code without conflict, it is even possible to use otherwise reserved words. Oviously the only thing you cannot have is a #define (or #macro) with one of these words, procedures, enums, variables, constants are not affected.
Code: Select all
namespace xyz
...
private function abc(...)
...
end namespace
#macro array(a, b, c...)
xyz.##a(b, c...)
#endmacro
array(abc, arg1, arg2, ...)
An audio extension (Angros47´s sound features ?) could be implemented like this:
audio(control, ...)
audio(set, ...)
audio(play [, ...])
audio(midi, ...)
audio(sound, ...)
...
maybe some more like:
audio(stop)
audio(pause)
audio(record)
requires the word "audio" in the main namespace, all the rest is hidden in a namespace
And the same syntax could be re-used for a video extension (or any other future extension)
video(play [, ...])
video(stop)
video(pause)
video(record)
...
Summary: only one single new keyword in the main namespace ("array", activated by including the corresponding include file) allows for an expandable new feature set for arrays (or other new features), without the need for the explicit namespace syntax. Nevertheless all new functions, constants, etc. live in their own namespace.
JK