CHAPTER 2
Perl Module Basics
S
PAGHETTI CODE
if you don't know what it means, you're probably writing it.
Spaghetti code gets its name from the numerous and thoroughly knotted paths
your program takes through its source code. In the classic case, every subroutine
in the program will call every other subroutine at least once (if there are subrou
tines goto is marinara for spaghetti code). Nothing is commented, or if it is, then
the comments are misleading. Executable code is mixed in with subroutine decla
rations at random. Basically, it's your worst nightmare.
What makes spaghetti code so bad is that even a small change in one part
of the program can have dire consequences in an unrelated area. Fixing bugs
becomes a dangerous activity find one, and two more spring from the mist. Code
like this invariably gets rewritten rather than enhanced, at tremendous expense.
To combat spaghetti code, you need modular programming. Modular pro
gramming is the practice of breaking a large program into smaller pieces called
modules. Each module offers its service through a well documented interface. The
internals of the module are considered private, or encapsulated.
The beauty of modular programming is that the internals of the module can
change without affecting code that uses the module. Fixing bugs is usually just a
matter of finding the offending code and making sure that the fix doesn't affect the
interface. Furthermore, modular programming makes your job easier; you only
need to worry about the implementation of a single module at a time, rather than
an entire complex program.
21
footer
Our partners:
PHP: Hypertext Preprocessor Best Web Hosting
Java Web Hosting
Inexpensive Web Hosting
Jsp Web Hosting
Cheapest Web Hosting
Jsp Hosting
Cheap Hosting
Visionwebhosting.net Business web hosting division of Web
Design Plus. All rights reserved