Reputation: 57
I want to use the procedures in a .tcl file which is "available" as a package and a namespace.
I am unable to differentiate b/w 'package require' & 'namespace import'
Upvotes: 0
Views: 417
Reputation: 137767
They're completely separate concepts.
A namespace is a code construct for containing commands and variables. And other namespaces. (There's a few other things too, but those are the main ones.)
A package is a collection of files that provides a defined, versioned API. It's an abstraction above just source
ing and load
ing individual files, which should be considered to be normally just part of the implementation of the package.
It's usually good practice to either keep all commands and variables defined by a package in a namespace with the same name, or for the package to define a single command with the same name as the package. This cuts the amount of confusion! However, this is just evolved good practice and there's many packages that don't work this way, often because they really originally predate the whole package mechanism; changing everything to be hyper-correct with some best practice isn't as good as maintaining compatibility with existing code, of course.
Use namespaces to organize the implementation of your code. Use packages to split the code up into pieces with defined tasks that you can evolve independently. These are totally orthogonal.
Upvotes: 1