Guidelines for writing big Tcl applications

Guidelines for writing big applications in Tcl

Lectus: Even though Tcl is a scripting language, it has been used for large projects as a full programming language. I created this page to discuss what are the general guidelines for writing big applications in Tcl.

I'll try to write some here from my experience. I'd like if people contributed their own ideas here. So far I think these ones are very important:

  • Use namespaces to separate your escope from other packages (see [namespace eval])
  • Make use of packages for reusable parts of your project (see [package provide])
  • Use a naming convention for your variables. For example: camelCase, underlined_variables, etc.
  • Use procs to split the functionality and make it easy to read and maintain.
  • Use pre-tested widgets and packages when possible.
  • Write pseudo-widgets to encapsulate the logic of your code that is application specific.
  • Make sure your code generates events (see uevent) to ease future extensions and modularity.
  • When writing packages, encapsulate with objects, at least follow the "tk-style" calling conventions.
  • Separate big monolithic processes into several processes that will talk to one another to perform the task.
  • Use the catch or try commands to handle errors.
  • Write lots of good comments.
  • Write documentation for your software.
  • Don't repeat yourself.

Anything else? Please contribute to this page! EF Added a few advices to the list, these are directly inspired by my work within myJoice .

nem Principles of organising large software projects are similar for most languages, chief of which would be to try and avoid writing large software projects! Number of bugs is almost always proportional to the size of the code base in any language. Of course, Tcl excels here in letting you write concise, readable code. Domain-specific language comes to mind. Another tip is to cleanly separate the core "domain model" of your application (as in a DSL) from the presentation (Tk/Web) or database access etc.