The Joy of Modularization

Posted on in Programming

orbitModern programs are not developed as singular, autonomous applications. Programmers have learned that many different programs use the same routines over and over again. By developing these routines as independent modules or libraries, programmers gain the advantage of quickly adding functionality to their programs. Modularization allows the detail of often-repeated code to be abstracted from an application so that programmers can concentrate on the details of what makes that application unique. Additionally, by using tested libraries, programmers gain the benefit of code that has been proven to be reliable (Farrell, 2008).


Let's assume that I am building a new invoicing application in Perl. The end-user is expecting an interface that allows them to enter customer information and generate invoices. The users are not going to use a web interface, so the application must present a graphical user interface on their desktops. It is hoped that address data can be validated at the time of entry so that invoices can be mailed with less fear of return. Finally, invoices should be generated in PDF format so that they can be saved or emailed.

Perl does not include a native graphical user interface. Since creating a windowing interface from scratch is outside the skill set of most programmers, a library was created to add graphical user interface functionality to Perl. The Perl/Tk module incorporates the Tk interface originally created for the Tcl programming language into Perl. Once loaded into the application, this module provides simple object-oriented methods for programmers to use in the development of their graphical user interfaces (Lidie & Walsh, 2002). The library is well written and should be usable without any modification.

There are many ways to provide physical address validation for an application. Rather than trying multiple methodologies and selecting the most appropriate, it is more efficient to select an existing library and incorporate it into the application. The Geo::PostalAddress library for Perl fits this bill. It provides methods for entering address information in a generic format and returning an address in a country specific format (Amma, 2005). The only functionality this library lacks is a way to check for the actual existence of an address. Although have a properly formatted address is useful when generating mailings, it would be even better if non-existent addresses were prevented from entering the system.

Finally, the creation of invoices in PDF format can be simplified by incorporating a PDF library into the application. One Perl module that can accomplish this is PDF::EasyPDF. This library is much less complicated than similar libraries, but it provides the basic functions necessary to generate invoices (Howe, 2006). Its simplicity may become a burden if the application grows beyond its intended functionality, but it is more than sufficient for the limited requirements set forth in the initial design phase.

Independently, these libraries are not very useful. When combined in a single application, they provide important functionality that might be impossible for the programmer assigned to the project. Even if the programmer has the skills to develop these libraries, reusing existing code will save time in coding and testing. In the end, it is preferable in most programming projects to reuse libraries rather than develop all facets of an application from scratch.


Amma, P. (2005). Geo::PostalAddress - Country specific postal address parsing / formatting. Retrieved August 6, 2009.

Farrell, J. (2008). Programming logic and design, comprehensive (5th ed.). Boston: Thomson Course Technology.

Howe, M. (2006). PDF::EasyPDF - PDF creation from a one-file module, with postscript-like controls. Retrieved August 6, 2009.

Lidie, S. & Walsh, N. (2002). Mastering Perl/Tk. Sebastopol, CA: O'Reilly.

Slaptijack's Koding Kraken