Skip to Main Content
Learning Perl/Tk
book

Learning Perl/Tk

by Nancy Walsh
January 1999
Beginner content levelBeginner
373 pages
9h 43m
English
O'Reilly Media, Inc.
Content preview from Learning Perl/Tk

1.12. Naming Conventions for Widget Types

Naming conventions? How boring! Well, sometimes our programs get so large and unwieldy that we can't remember what that stupid $button variable was pointing to. If there are over 10 buttons in our program, we would be hard-pressed to figure out which button was $button3 without digging through a bunch of code.

I'm merely going to suggest a naming convention, and if you like it, please use it! If not, either come up with your own, or hope you have a really good memory.

For buttons, I like to use _b, _bttn, or Button as a type of qualifier to the variable name. For instance, I would name my button in the Hello World example $done_b, $done_bttn, or$doneButton.

A specialized widget type is the very first window we create with the MainWindow method. I always use $mw as the variable name for this. You will see other programs use $main or $mainwindow as well.

Table 1.1 contains a list of widget types and my suggested naming conventions for them. Replace "blah" with a sensible description of the widget's purpose (e.g., exit). If you use this convention, you'll always know what type of widget you're working with.

Table 1.1. Naming conventions by widget type
Widget Type Suggested Name Examples
Button $blah_b (or $blah_bttn, $blahButton) $exit_b, $apply_b, $newButton
Canvas $blah_canvas or $blahCanvas $main_canvas, $tinyCanvas
Checkbutton $blah_cb or $blahCheckbutton $uppercase_cb, $lowercaseCheckbutton
Entry $blah_e or $blahEntry $name_e, $addressEntry ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering Perl/Tk

Mastering Perl/Tk

Stephen Lidie, Nancy Walsh

Publisher Resources

ISBN: 1565923146Supplemental ContentCatalog PageErrata