Having recently posted Activity timer / chess clock, I am reviewing what I have learned from writing this program, and how I can improve it if I had to start again.

In particular, all the state information is held in main program scoped lexicals - I could have used main:: package variables, but I am too much of a diehard to consider omitting use strict.

It could be possible to pass everything in via parameters, but most of these need to be determined at event time, not at bind time. I could have used anonymous subs, and use closures to hold state information. Even so, there are some functions such as Menu=>Button=>Next, which would be very difficult to implement.

So, leaving the program as it is, we have global or quasi-global variables. To avoid this would result in less clear, more obfuscated code. Which is better programming style?

Is there some trick with Tk and/or parameter passing that I have missed, which is both clear and clean?

Any feedback would be appreciated.


In reply to 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.