Version 0 of Compact Code Formatting Style

Updated 2007-09-05 22:40:25 by LEG

The code formatting style used for Tcl programs as reflected on the man pages and elsewhere is similar to C Code formatting.

After reading (once again) '1% the code' [L1 ] and while writing (once again) a medium size Tcl application i started to think, that there are to many braces in the files. Python [L2 ] does without them, however Python lacks nice Syntax at other points, I won't discuss this here.

Some rules:

  • no lonly braces on a single line, except:
  • when a namespace, or a proc larger then 24 lines (buh) ends, or
  • for delimiting data
  • braces in if {expr} only when it is an expresion
  • braces around arguments only if there are more then one

Some recomendations:

  • rather return, continue, break then else

(well, that was just one)

Examples:

 proc ccfs param {
     if !$param return
     puts "we are in"

     if [llength $param] {
        puts "and we've got a list"}

     switch -- [lindex $param] {
         stop {return}
         continue {
             # test the second parameter 
             set test [lindex $param 1]}
         default {puts "don't know what todo with: $param}}}
    if {$test eq "stop"} {
        puts "we stopped on the second param"}}

 proc ccfs1 {varA varB} {...}