<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE TIP SYSTEM "http://tcl.activestate.com/cgi-bin/tct/tip/tipxml.dtd">
<!-- Converted at Thu Feb 09 11:57:55 GMT 2012 -->
<!-- TIP AutoGenerator - written by Donal K. Fellows -->

<TIP number='44'>
<header><title>Move Tk&apos;s Private Commands and Variables into ::tk Namespace</title><author address="mailto:dgp@users.sourceforge.net">Don Porter</author><status type='project' state='final' tclversion="8.4" vote='after'>$Revision: 1.9 $</status><history></history><created day='16' month='jul' year='2001' /></header>
<abstract>This TIP proposes that Tk&apos;s private commands and variables be moved into the namespace <emph style="italic">::tk</emph> or its descendent namespace(s).</abstract>
<body><section title="Background">
<para>Tk defines several commands and variables in the global namespace that are not intended for public use. Some of the commands are used for widget bindings. Some of the variables are used to maintain widget state information. The definition of these &quot;private&quot; commands and variables in the global namespace is a legacy held over from Tk 4 and the pre-8 versions of Tcl in which there was only one namespace.</para>
<para>Fortunately, the coders of Tk have maintained good discipline in naming these commands and variables intended for Tk&apos;s internal use only. The commands and variables matching the glob pattern <emph style="italic">::tk[A-Z]*</emph> are private. Consider this interactive tktest session with Tk 8.3.3:</para>
<verbatim><vline encoding='base64'>ICQgY2QgdGsvdW5peA==</vline><vline encoding='base64'>ICQgbWFrZSBydW50ZXN0</vline><vline encoding='base64'>IC4uLg==</vline><vline encoding='base64'>ICUgIyBQdXQgVGsgdGhyb3VnaCBpdHMgcGFjZXMgdG8gZGVmaW5lIGFsbCBjb21tYW5kcyBhbmQgdmFyaWFibGVz</vline><vline encoding='base64'>ICUgc291cmNlIC4vLi4vdGVzdHMvYWxsLnRjbA==</vline><vline encoding='base64'>IC4uLg==</vline><vline encoding='base64'>ICUgbGxlbmd0aCBbaW5mbyBjb21tYW5kcyB7dGtbQS1aXSp9XQ==</vline><vline encoding='base64'>IDE4Mw==</vline><vline encoding='base64'>ICUgbGxlbmd0aCBbaW5mbyB2YXJzIHt0a1tBLVpdKn1d</vline><vline encoding='base64'>IDU=</vline></verbatim>
<para>So, on Unix, there are 183 private commands and 5 private variables polluting the global namespace. The number and list of commands and variables varies a bit from platform to platform due to differences in widget bindings.</para>
<para>More recently, private commands in Tk have been added in the <emph style="italic">::tk</emph> namespace; two examples are <emph style="italic">tk::PlaceWindow</emph> and <emph style="italic">tk::SetFocusGrab</emph>. Likewise the private variable <emph style="italic">tk::FocusGrab</emph> has also been added in the <emph style="italic">::tk</emph> namespace.</para>
<para>There are three reasons why it is better for Tk&apos;s private commands and variables to be moved out of the global namespace and into the <emph style="italic">::tk</emph> namespace.</para>
<enumerate><item.e index='1'><para>The large number of commands and variable makes it more difficult to use interactive <emph style="italic">[info commands]</emph> and <emph style="italic">[info vars]</emph> or <emph style="italic">[info globals]</emph> introspection to learn about what application specific commands and variables are defined.</para></item.e><item.e index='2'><para>Placing private commands and variables in the global namespace gives them a higher profile, and increases the likelihood that they will be used publicly, against the intent of Tk&apos;s interface.</para></item.e><item.e index='3'><para>By making more use of its own namespace for keeping track of its own internals, Tk becomes a better example for authors of other packages to copy.</para></item.e></enumerate>
</section>
<section title="Proposal">
<para>All commands and variables created by Tk and matching the glob pattern <emph style="italic">::tk[A-Z]*</emph> shall be renamed to a name contained within the <emph style="italic">::tk</emph> namespace or one of the descendent namespaces of <emph style="italic">::tk</emph>.</para>
<para>The global variable <emph style="italic">::histNum</emph> created by <emph style="italic">tk/library/console.tcl</emph> shall also be renamed to <emph style="italic">::tk::HistNum</emph>.</para>
<para>All commands and variables created by the proposal will be given names that begin with an uppercase character (<emph style="italic">[A-Z]</emph>) to indicate their internal status according to the conventions of the Tcl Style Guide [<url ref="http://purl.org/tcl/home/doc/styleGuide.pdf"/>].</para>
</section>
<section title="Compatibility and Migration">
<para>This proposal only deals with the internals of Tk, so technically there are no compatibility issues, because Tk users should not be depending on these private commands and variables.</para>
<para>That said, because these commands and variables have had a high profile in the global namespace, it seems likely that some users have written code that depends on them. To aid such users in a migration away from that dependence, it is also proposed that Tk provide two additional unsupported commands:</para>
<verbatim><vline encoding='base64'>IDo6dGs6OnVuc3VwcG9ydGVkOjpFeHBvc2VQcml2YXRlQ29tbWFuZCBjb21tYW5kTmFtZQ==</vline></verbatim>
<para>and</para>
<verbatim><vline encoding='base64'>IDo6dGs6OnVuc3VwcG9ydGVkOjpFeHBvc2VQcml2YXRlVmFyaWFibGUgdmFyaWFibGVOYW1l</vline></verbatim>
<para>The command <emph style="italic">[::tk::unsupported::ExposePrivateCommand commandName]</emph> restores the existence of the Tk private command <emph style="italic">commandName</emph> in the global namespace as it was before adoption of this proposal. The command <emph style="italic">[::tk::unsupported::ExposePrivateVariable variableName]</emph> restores the existence of the Tk private variable <emph style="italic">variableName</emph> in the global namespace as it was before adoption of this proposal. For example, a Tk user who had written code that made use of the Tk private command <emph style="italic">tkCancelRepeat</emph> can add the following code to continue working with Tk after acceptance of this proposal:</para>
<verbatim><vline encoding='base64'>IGlmIHshW2xsZW5ndGggW2luZm8gY29tbWFuZHMgdGtDYW5jZWxSZXBlYXRdXX0gew==</vline><vline encoding='base64'>ICAgICB0azo6dW5zdXBwb3J0ZWQ6OkV4cG9zZVByaXZhdGVDb21tYW5kIHRrQ2FuY2VsUmVwZWF0</vline><vline encoding='base64'>IH0=</vline></verbatim>
<para>These migration commands are in the namespace <emph style="italic">tk::unsupported</emph>, a new namespace to be used for unsupported commands in Tk. This namespace may and should be used for any other unsupported commands to be created in Tk. Their implementation is in the new file <emph style="italic">tk/library/unsupported.tcl</emph>.</para>
</section>
<section title="Reference Implementation">
<para>This proposal has already been implemented and committed to Tk&apos;s CVS repository on the branch tagged <emph style="italic">dgp-privates-into-namespace</emph>. That branch is up to date with Tk&apos;s HEAD branch as of July 16, 2001.</para>
<para>To make an anonymous checkout of the reference implementation into a directory named <emph style="italic">tkprivate</emph>, run the following CVS commands:</para>
<verbatim><vline encoding='base64'>ICQgY3ZzIC1kIDpwc2VydmVyOmFub255bW91c0BjdnMudGt0b29sa2l0LnNmLm5ldDovY3Zzcm9vdC90a3Rvb2xraXQgXA==</vline><vline encoding='base64'>ICAgbG9naW4=</vline><vline encoding='base64'>IChMb2dnaW5nIGluIHRvIGFub255bW91c0BjdnMudGt0b29sa2l0LnNmLm5ldCk=</vline><vline encoding='base64'>IENWUyBwYXNzd29yZDogPEVudGVyPg==</vline><vline encoding='base64'>ICQgY3ZzIC16MyAtZCA6cHNlcnZlcjphbm9ueW1vdXNAY3ZzLnRrdG9vbGtpdC5zZi5uZXQ6L2N2c3Jvb3QvdGt0b29sa2l0IFw=</vline><vline encoding='base64'>ICAgY28gLXIgZGdwLXByaXZhdGVzLWludG8tbmFtZXNwYWNlIC1kIHRrcHJpdmF0ZSB0aw==</vline></verbatim>
<para>The reference implementation has the same results on the Tk test suite as the HEAD revision.</para>
<para>In the tktest of the reference implementation:</para>
<verbatim><vline encoding='base64'>ICQgbWFrZSBydW50ZXN0</vline><vline encoding='base64'>IC4uLg==</vline><vline encoding='base64'>ICUgc291cmNlIC4vLi4vdGVzdHMvYWxsLnRjbA==</vline><vline encoding='base64'>IC4uLg==</vline><vline encoding='base64'>ICUgbGxlbmd0aCBbaW5mbyBjb21tYW5kcyB7dGtbQS1aXSp9XQ==</vline><vline encoding='base64'>IDA=</vline><vline encoding='base64'>ICUgbGxlbmd0aCBbaW5mbyB2YXJzIHt0a1tBLVpdKn1d</vline><vline encoding='base64'>IDA=</vline></verbatim>
</section>
<section title="See Also">
<para>Feature Request 220936 [<url ref="http://sf.net/tracker/?func=detail&amp;aid=220936&amp;group_id=12997&amp;atid=362997"/>]</para>
</section>
<section title="Related Ideas / Future Work">
<para>The ideas in this section are <emph style="italic">not</emph> part of this proposal. They are related ideas mentioned here as explicitly outside the scope of this proposal so they will not be counter-proposed.</para>
<itemize><item.i><para><emph style="italic">Shouldn&apos;t Tk&apos;s public commands and variables be moved to ::tk too?</emph></para><para>Well, yes, I think they should, but that change clearly involves sorting out more difficult compatibility/migration issues. The current proposal is limited to the less controversial topic of Tk&apos;s private commands and variables. We&apos;ll tackle the rest later.</para></item.i><item.i><para><emph style="italic">Shouldn&apos;t Tk make use of [namespace code] in its bindings?</emph></para></item.i><item.i><para><emph style="italic">Wouldn&apos;t it make Tk better organized if commands like [tk::IconList_Add] were further renamed [tk::IconList::Add]?</emph></para><para>Perhaps so. There may be many ways in which Tk can and should make better or more idiomatic use of namespaces. That&apos;s not the point of this proposal, though. The point is to get these commands and variables out of the global namespace. Once that is accomplished, then these other matters are unquestionably internal and can proceed at the discretion of the maintainers without further TIP review.</para></item.i></itemize>
</section>
<section title="Copyright">
<para>This document has been placed in the public domain.</para>
</section>
</body></TIP>

