Grupos de Google ya no admite nuevas publicaciones ni suscripciones de Usenet. El contenido anterior sigue siendo visible.

Package namespace absolute or relative

Visto 40 veces
Saltar al primer mensaje no leído

Harald Oehlmann

no leída,
16 mar 2018, 6:21:3216/3/18
a
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

no leída,
18 mar 2018, 2:32:0618/3/18
a
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

no leída,
18 mar 2018, 14:35:4518/3/18
a
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

no leída,
18 mar 2018, 17:40:3118/3/18
a

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 mensajes nuevos