Version 1 of _namespace import_ and _rename_

Updated 2010-10-21 09:50:07 by dkf

In a comp.lang.tcl posting [L1 ] Donald Porter gives a very nice example of the freedom that the programmer gains through the proper use of namespaces.

The example speaks for itself:

 # Someone provides the thread package with a thread::shared command:
 namespace eval thread {
        namespace export shared
        proc shared {option args} {...}
 }

 # Author of the foo package has different opinions about names:
 namespace eval foo {
        namespace import ::thread::shared
        # Shared what?  What a stupid ambiguous name!
        rename shared sharedVariable
        proc myLongCommandName {} {...; sharedVariable set counter 1; ...}
 }

 # Author of the bar package has yet a third view:
 namespace eval bar {
        namespace import ::thread::shared
        # Stpd thrd pkg gonna give me RSI.
        rename shared sv
        proc x {} {...; sv set x 1; ...}
 }