Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Package namespace absolute or relative

40 views
Skip to first unread message

Harald Oehlmann

unread,
Mar 16, 2018, 6:21:32 AM3/16/18
to
Dear TCL'ers,

a package file: "mypackage.tcl" contains the tcl package "mypackage".

Is it wise/correct to use absolute namespace or relative namespace
within package, e.g. preceed the namespace with "::".

Example with relative namespace:

package provide mypackage 1.0
namespace eval mypackage {
variable myvar 1
}
proc mypackage::myproc {args} {
variable myvar
...
}

Example with absolute namespace:

package provide mypackage 1.0
namespace eval ::mypackage {
variable myvar 1
}
proc ::mypackage::myproc {args} {
variable myvar
...
}

What are the implications of each choice ?

Thank you,
Harald

Ashok

unread,
Mar 18, 2018, 2:32:06 AM3/18/18
to
Harald,

I've asked myself the same question before. I like the idea of loading
under a namespace that can be controlled by the caller. The issue I have
is that other packages that also make use of the functionality then do
not know how to invoke those commands.

For example, if the sha package is loaded under ::myapp::sha namespace,
then the pki package which may also make use of that functionality does
not really know it needs to call ::myapp::sha::sha1.

So currently I prefer to always start with the global namespace.

/Ashok

Harald Oehlmann

unread,
Mar 18, 2018, 2:35:45 PM3/18/18
to
Ashok,

thank you for your thoughts. This is higly appreciated. And I am happy
that I am not alone ;-)

So this is a clear +1 for "::namespace".

Thank you,
Harald

Gerald Lester

unread,
Mar 18, 2018, 5:40:31 PM3/18/18
to

I go for absolute namespace, for the reasons Ashok stated.

IF we had a way to state that a package could be loaded multiple times
or maybe once per namespace -- then maybe I'd go with relative namespaces.
--
+----------------------------------------------------------------------+
| Gerald W. Lester, President, KNG Consulting LLC |
| Email: Gerald...@kng-consulting.net |
+----------------------------------------------------------------------+
0 new messages