< Day Day Up > |
Hour 17. Writing ModulesWhat You'll Learn in This Hour:
In Hour 8, "Functions," you learned about subroutines. Subroutines allow you to take a frequently used pieces of code and assign it a name to create a small self-contained "mini-program" with its own variables . After you've written enough programs, you'll find yourself creating the same functions over and over again for tasks . If you write a lot of file-manipulation programs, you'll probably have code to lock files and unlock them in several places; programs with user interaction (prompts and input) will have functions to display prompts, wait for answers, and reject bad input; and programs that work with a particular database might have functions for reading, writing, and editing data. If every program contained copies of the required functions, cut-and-pasted into the program, your programs would soon become unwieldy to maintain because
Instead programmers have settled on the concept of function libraries . Every programming language and system has them. Sometimes they're called libraries, modules, or archives. For example, with operating systems, Microsoft Windows systems have dynamically linked libraries (DLLs) and Linux systems have shared libraries. Perl's method of storing collections of functions is called a module . Entire books have been written on creating modules and function libraries. In this hour, you're going to explore writing modules to accomplish a few simple goals, namely making your code easier to maintain, share, and debug. |
< Day Day Up > |