[PD-dev] Tcl/Tk code formatting and file organization

Hans-Christoph Steiner hans at eds.org
Sun Jan 4 02:39:39 CET 2009


On Jan 3, 2009, at 1:48 PM, Miller Puckette wrote:

> Sorry for the slow response on this one...
>
>> - first, does anyone object to making the Tcl files use 90 or 100
>> character widths?  Tcl lines tend to be long and 80 char width tends
>> to cause a lot of really ugly lines.
>>
>
> This would cause me much misery since I often depend on 'terminal'  
> editors
> that can't be conveniently reformatted by file.  Plus, it's hard to  
> know where
> to draw the line.

I also regularly edit files with emacs and vi in the terminal, and 90  
chars has never caused me any trouble.  xterm, rxvt, etc. etc. all  
handle it very well.  Or are you talking about using computers in  
80x25 character display mode?  Are you on a VT100?  ;-)

There are some really unreadable sections of u_main.tk that would be  
more readable with a bit more room, like 90 chars.  I am fine with  
leaving the C code at 80 chars, but Tcl tends to have a lot of long  
lines, and often doesn't wrap cleanly.

>> - second, I think we should use a similar tab format as the C side,
>> but cleaner: 4 char tabs, all spaces or maybe all tabs.
>>
> I've "always" used 4-character indents, no tabs (except for  
> makefile.in :)
> Various contributed code deviates from that, and when I have to  
> actually look
> at it I feel at liberty to thrash it into the pd "standard".  There  
> are some
> bits I'm afraid to touch, such as the ALSA MIDI code, since I don't  
> have any
> setup on which to test it.
>
> I think it causes great confusion to use hard tabs in the code.  If  
> they're
> absolutely unavoidable let's keep them to 8 spaces (the most  
> standard value
> even if it doesn't agree with the indentation style.)

All spaces then?  4 char indent?

>> - third, I am thinking that the Tcl should be broken up into single-
>> file packages where the package name and the file name are the same.
>> For example:
>>
>> pd.tk
>> menus.tcl
>> menucommands.tcl
>> bindings.tcl
>> preferences.tcl
>> ...
>>
>> or maybe:
>>
>> pd.tk
>> pdmenus.tcl
>> pdmenucommands.tcl
>> pdbindings.tcl
>> pdpreferences.tcl
>> ...
>
> but 'pd' is understood - it's the name of the program.  On the other  
> hand, "u"
> is opaque as a prefix.  "g" is taken.  Maybe "t", as in "t_pd.tk",  
> etc.
> Also, unless there's a reason to have some named ".tk" and others  
> ".tcl" they
> should share the same suffix to make globbing easier.

The "pd_" is not understood in Tcl.  If you have a package/namespace  
called "menus", that is very vague and has a very high potential for  
causing name conflicts.  "pd_menus" is much clearer in meaning and  
much less likely to cause name conflicts.  "t_" seems pretty much  
meaningless to me, especially since the files end with ".tcl".

.tk is for wish shell, and .tcl is for tclsh and packages, so those  
different endings have meaning.  pd.tk is run with the Wish shell.  It  
could be pd.tcl, as long as there is a "package require Tk", which  
will then launch the Wish shell stuff.  I don't know if that would  
play nice with the Wish.app on Mac OS X.

.hc

> Historical note: the reason the makefile copies the tk script is so  
> that all
> the source could live in the same directory, but so that the runtime  
> wouldn't
> look in the source directory in case someone wants to install the  
> two in
> separate places (as in redhat's "rpm" and "srpm" setup).
>
> cheers
> Miller
>
>>
>> ------------------------------------------------------------------------
>> ----
>>
>> The arc of history bends towards justice.     - Dr. Martin Luther
>> King, Jr.
>>
>>
>>
>> _______________________________________________
>> Pd-dev mailing list
>> Pd-dev at iem.at
>> http://lists.puredata.info/listinfo/pd-dev





More information about the Pd-dev mailing list