From personal experience, code using Tk invariably seems to end up fairly horrible to look at.

The structure of the parameters passed to the procedures, and the seeming large number of these, leads either to a large number of "temporary" variables to store them, which simply leads to confusion when it comes to maintenance, or to code which seems definitively unclear.

From having written a number of fairly large Tk programs, I've developed, and try to stick to, a style of careful spacing when it comes to defining and using widgets. While I'm not certain this is the best method of writing a script, it does serve to make the previously horrible-to-look-at calls much cleaner, with obvious benefits when debugging and maintaining the code.

I do make use of global variables with Tk, simply because it makes the use of subs to carry out functions much easier. Avoiding this, as you say, results in fairly unclear code.

I personally think that neither style is definitively "better". If the script can be easily understood, maintained and extended, then whichever style has been used is obviously the better one. This, I think, depends muchly on the length and complexity of the script, and is something best determined while thinking about the overall design of the program.

I guess my opinion is to try and keep stuff as simple as possible, when it comes to layout, variable referencing and parameter passing, hopefully giving something that you can work from in the future.

Just some quick thoughts ..
--Foxcub


In reply to Re: Tk programming style by Tanalis
in thread Tk programming style by rinceWind

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.