FREE Newsletter Home Authoring ... Email a Colleague Active Server Pages JSP/Java Servlets Microsoft SQL Server Daily Backup Dedicated Servers Streaming Audio/Video 24-hour Support Click Here Hot Topics JavaScript HTML CSS DHTML ... XML find a web host with: CGI Capabilities Cold Fusion Dedicated Servers JSP/Java Servlets MySQL Preinstalled CGI Scripts advanced search Developer Channel FlashKit HierMenusCentral Java Boutique JavaScript.com ... XMLFiles.com e-commerce Web Search Calling Cards Submit Your Site Vacations ... Best Deals on PDAs! internet.com Developer Downloads International Internet Lists ... E-mail Offers Prototypes - Page 14 Wrox Press July 13, 2001 The subroutines we have considered so far exert no control over what arguments are passed to them; they simply try to make sense of what is passed inside the subroutine. For many subroutines this is fine, and in some cases allows us to create subroutines that can be called in a variety of different ways. For example, we can test the first argument to see if it is a reference or not, and alter our behavior accordingly. However, we are not enforcing a calling convention, so we will only discover our subroutines are being called incorrectly when we actually execute the call, and then only if we have written the subroutine to check its arguments thoroughly. Since some subroutine calls may not occur except under very specific circumstances, this makes testing and eliminating bugs very difficult. Fortunately there is a way to define compile-time restrictions on the use of subroutines through the use of prototype definitions. Although entirely optional, by specifying the types of the expected parameters, prototypes can eliminate a lot of the problems involved in ensuring that subroutines are called correctly. This allows us to specify what parameters a subroutine takes (scalars, lists/hashes, or code references), and whether a parameter can be either a simple literal value, or whether it must be an actual variable. Good use of prototypes early in the development process can be invaluable. | |
|