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

How to set up a modular Tcl/Tk project

108 views
Skip to first unread message

Arie van Wingerden

unread,
May 16, 2019, 5:03:44 AM5/16/19
to
Having read about the newish features like namespaces and OO in latest Tcl/Tk releases, I'd like to know a bit more about modular setup of a project.

Are there guidelines for setting up a new project with multiple source files in relation to the use of namespaces and also how to deploy such project as starkit?

Bear with me: i am a long time developer but completely new to Tcl/Tk.

Tia!

Arjen Markus

unread,
May 16, 2019, 6:53:35 AM5/16/19
to
Well, one resource, although less organised than perhaps desirable ;), is the Wiki - https://wiki.tcl-lang.org. You will find many examples of Tcl/Tk programs, techniques and so on.

To answer your immediate questions or at least provide a bit of a guide:

Source files may contain any number of procedures, namespaces, TclOO classes - it is up to you to organise your code into manageable files. As a rule of thumb, I put the procedures belonging to a namespace into their own file, so that there is one namespace in that file. But if the file gets too large, it is no problem to distribute the namespace and its procedures over several files. (That is in fact the organisation of my Plotchart package in Tklib. Other large packages such as Tablelist do that as well.)

Namespaces can be used to organise procedures and variables into smaller units than the whole program. The advatage is that you can only call a procedure if its name is fully qualified (includes the namespace it belongs to) or if you deliberately import procedures from a namespace. That way you have more control.

Of course, TclOO goes a step further: the methods of a class can only be called via objects belonging to the class.

Starkits are a technique to pack all the source code (and binary libraries) into a single executable file. As that file includes the Tcl/Tk run-time, you have no need to install Tcl/Tk on the target machine, making deployment a lot easier.

The Wiki has a bunch of links to articles focusing on certain aspects of Tcl/Tk as well links to books, both recent and somewhat older.

Regards,

Arjen

two...@gmail.com

unread,
May 16, 2019, 12:59:10 PM5/16/19
to
On Thursday, May 16, 2019 at 2:03:44 AM UTC-7, Arie van Wingerden wrote:
> Having read about the newish features like namespaces and OO in latest Tcl/Tk releases, I'd like to know a bit more about modular setup of a project.
>
> Are there guidelines for setting up a new project with multiple source files in relation to the use of namespaces and also how to deploy such project as starkit?


I highly recommend the book by Ashok, a frequent contributor
here. The pdf version of the book is a great and is an
up to date resource. Lots of material on OO, namespaces,
and starkits. Searchable and nicely formatted. Easy to follow
and try out the examples as you go.

Title: The Tcl Programming Language

https://gumroad.com/l/tclprog

Alex Plotnikov

unread,
May 16, 2019, 1:12:54 PM5/16/19
to
Here is a very good example of real project where you would probably know of 'how to make a big Tcl project' with all those modules/namespace/OO issues:

https://www.tclcommunityassociation.org/wub/proceedings/Proceedings-2007/proceedings/applications/final_WHD_Tcl_2007.pdf

The only thing that can embarrass you a bit is the Snit (now not in Tcl core), but if you've mastered the TclOO of Tcl core, e.g. through https://www.magicsplat.com/articles/oo.html or preferably through the Tcl book of Ashok P. Nadkarni, the Snit matters should be clear for you.

Though the project is warlike. Hopefully, yours would be of other type...

mango

unread,
May 16, 2019, 2:15:53 PM5/16/19
to
On Thursday, May 16, 2019 at 2:03:44 AM UTC-7, Arie van Wingerden wrote:
> Having read about the newish features like namespaces and OO in latest Tcl/Tk releases, I'd like to know a bit more about modular setup of a project.
[snip]
> Tia!

Although rather old, I think Will Duquette's namespace guide contains a lot of good practical advice.

http://www.wjduquette.com/tcl/namespaces.html

Gerald Lester

unread,
May 16, 2019, 11:04:29 PM5/16/19
to
Well, having worked with three large products (each over 500K LOC) over
the years, I can share some insights.

1) At most one namespace per file.
2) Make (or another build system) is your friend.
3) Packages/modules are your friend.

In general, both products had a directory with the same name as the
namespace and a one or more tcl files inside of it. A make file append
all of the files in the directory into a namespace.tcl file that
included the creation of the namespace at the top of the file.

Feel free to email me directly if you want some more guidance.

--
+----------------------------------------------------------------------+
| Gerald W. Lester, President, KNG Consulting LLC |
| Email: Gerald...@kng-consulting.net |
+----------------------------------------------------------------------+

Gerald Lester

unread,
May 16, 2019, 11:07:09 PM5/16/19
to
On 5/16/19 10:04 PM, Gerald Lester wrote:
> On 5/16/19 4:03 AM, Arie van Wingerden wrote:
>> Having read about the newish features like namespaces and OO in latest
>> Tcl/Tk releases, I'd like to know a bit more about modular setup of a
>> project.
>>
>> Are there guidelines for setting up a new project with multiple source
>> files in relation to the use of namespaces and also how to deploy such
>> project as starkit?
>>
>> Bear with me: i am a long time developer but completely new to Tcl/Tk.
>
> Well, having worked with three large products (each over 500K LOC) over
> the years, I can share some insights.
>
> 1) At most one namespace per file.
> 2) Make (or another build system) is your friend.
> 3) Packages/modules are your friend.
>
> In general, both products had a directory with the same name as the
> namespace and a one or more tcl files inside of it.  A make file append
> all of the files in the directory into a namespace.tcl file that
> included the creation of the namespace at the top of the file.
>
> Feel free to email me directly if you want some more guidance.
>

For a paper on an early version of one of the products, see
http://www.tcl.tk/community/tcl1993/assets/talk54/Slides.pdf

Arie van Wingerden

unread,
May 19, 2019, 11:26:56 AM5/19/19
to
Thx for all answers and advice. Will dig in :-)

Op donderdag 16 mei 2019 11:03:44 UTC+2 schreef Arie van Wingerden:
0 new messages