Snowman has asked for the wisdom of the Perl Monks concerning the following question:

The company I work for has some perl coding guidelines which we need to enhance to include PerlTk.

I'm looking for suggestions for what is consider good practice when writing PerlTK scripts.

--
The Snowman
snowman@notreally.co.uk

Replies are listed 'Best First'.
Re: Perl Tk coding guidelines?
by Jouke (Curate) on Aug 09, 2001 at 17:24 UTC
    It depends a lot on the kind of coding guidelines you already have. I guess most of them are still valid when you code Perl/Tk, because it still *is* Perl.

    However, to improve readability of your Tk script I think it's good practice to keep your callbacks as compact as you possibly can, so either use a reference to a seperate subroutine, or use no more than 2 or three lines for it.

    Maybe if you gave a few of the guidelines you already have, we would be able to extend them for Tk.

    Jouke Visser, Perl 'Adept'
    Using Perl to help the disabled: pVoice and pStory
Re: Perl Tk coding guidelines?
by Starky (Chaplain) on Aug 09, 2001 at 20:34 UTC
    While the style guidelines would be the same as any non-Tk application, the design will be different.

    While design patterns are not applicable for all applications, for GUI applications, adopting a good design pattern (I recommend the Model-View-Controller (MVC) pattern) can improve your general sanity considerably.

    I would also strongly using OO Perl if you don't already. Trying to write a GUI app without proper encapsulation results in monolithic testaments to spaghetti and long sleepless nights in front of a monitor.

    With both these things in mind, I would recommend creating an object diagram and a sample class diagram, presenting them to the development team and incorporating them into your set of artifacts, and performing design reviews periodically to make sure folks conform to the standard model you choose.

    If you don't use UML right now, allow me to offer a plug: I find Dia a simple but stable and highly useful UML diagramming tool if you need to create some diagrams but don't need the full feature set of something like Rational Rose or Object Domain (which don't forward or reverse engineer Perl anyway). I think it comes default with most Red Hat installs these days ....

    Hope this helps :-)

Re: Perl Tk coding guidelines?
by Dr. Mu (Hermit) on Aug 10, 2001 at 11:19 UTC
    I've found that giving consistent names to widget objects helps readability. For example, begin the names of all button widgets with "$btn", as in $btnStart and $btnExit. This is especially helpful when reading someone else's code. At least you know at a glance what kind of object is being referred to.