Perl + Objects = Winning combination

Perl + Objects = Winning combination

am 10.04.2007 01:55:17 von paduille.4061.mumia.w+nospam

After writing a previous version of this program

http://home.earthlink.net/~mumia.w.18.spam/games_fever/index .html

I received feedback that the lightest of the green squares were
difficult to distinguish from the gray background. Fortunately, I'd
written the program in Perl-Tk using object oriented features.

I decided, for reasons of personal aesthetics, that I would make only
minimal changes to the color scheme. Instead of changing the colors, I
wanted to put a border around the "selected" squares--which are really
just Tk-labels.

The problem with borders is that they take up space. Any label that I
put a border around would be slightly larger than the labels around it
(if those others didn't also have borders), so I needed to put borders
around /all/ labels. My initial plan was to make all borders the same
color as the background (e.g. invisible border) and highlight labels by
making the border black; however, alas, Tk does not seem to allow a
Tk::Label to have a border of one color and font text in another color.
I came to the conclusion that Tk::Label wasn't going to do it.

This had the potential to stop my new feature right out of the starting
gate because all of my GUI code assumed that it was dealing with
Tk::Labels. I didn't want to rewrite all that code, so I needed to
subclass Tk::Label.

And it was the easiest thing in the world. I created a new object type,
YOYO::Label, that inherited from Tk::Label. That object consists of a
label within a frame; the frame has one color, and the label has
another. I now have perfect labels with black text and gray borders.

After adding to my program one 54-line module (YOYO::Label) and two
lines in the main program, I have the desired feature. And it took me
all of twenty minutes to add it, and ten of that was spent reading the
POD for Tk::Options.

Perl-Tk is *better* than TCL/TK. TCL is not object-oriented. I would've
written the first version of the program with TCL/TK Label widgets, and
when the change to a new type of label was needed, I'd have to do reams
of modifications in the main portion of the GUI code since there is no
subclassing in the procedural language TCL.

This is how programming is supposed to be done. Small changes should
require a small amount of work, and when you do OO right, that what you get.

Perl plus objects and Tk is a winning combination. Yahoo!

Re: Perl + Objects = Winning combination

am 10.04.2007 03:52:18 von Robert Hicks

On Apr 9, 7:55 pm, "Mumia W." +nos...@earthlink.net> wrote:
> Perl-Tk is *better* than TCL/TK. TCL is not object-oriented. I would've
> written the first version of the program with TCL/TK Label widgets, and
> when the change to a new type of label was needed, I'd have to do reams
> of modifications in the main portion of the GUI code since there is no
> subclassing in the procedural language TCL.
>

I happen to not agree here and I have used both. If you want OO with
Tcl you have XOTcl or Snit or iTcl. Better yet Tcl 8.5 is going to
have an minimist OO framework added to the core. Also with Tcl you get
all the changes to Tk at once. If you want that you have to use Tkx or
something similiar.

Robert