July 02, 2002
Debugging Web ApplicationsUnderstanding Code InternalsKnowing what to do to achieve perfect (or perfectly debuggable) code is one thing. Knowing what to expect and look for is another. There are many different models for Web application development and deployment environments. It's vital that you know exactly how yours works and how it differs from others you've worked with, so that you can adjust your analysis appropriately. For example, Java Server Pages (JSPs) are popular because to the developer, JSP code appears to be simple inline Java statements embedded in the context of an HTML documentsimilar to ASP or PHP. But once they're deployed, JSPs are actually compiled into servlets. Trying to isolate the cause of a symptom described by an unnerved and possibly furious end user can be mind-numbingly difficult unless you know how to look for the actual servlet code. Some other systems, such as Mason (a tool similar in architecture to JSP, but based on Apache and mod_perl), also let you inspect the actual code used to create the runtime component.
Bug-Free MarkupBeyond writing good, testable code, and being familiar with the environment in which the code will be executed, you should consider tools that will reduce the tedium and error-prone nature of debugging itself. For HTML and XHTML, there are many validators and emulators that can show you whether your markup is well-formed and valid. Validators can also suggest ways in which your application went wrong by showing you a representation of the visual display that the end user sees. These tools may be especially useful when the description of the symptom you received from a user of Browser XYZ doesn't resemble anything familiar. There are also validators for CSS stylesheets, syntax and lint checkers for JavaScript, and so on. But beyond simply providing assurances that the bug isn't in your markup, validators stop short of serious serious debugging. Fortunately, some basic CGI scripts and programs are so simple that they don't require much debugging. However, more complex CGIs, especially those using popular libraries like Lincoln Stein's CGI.pm or Thomas Boutell's cgic, may require extensive debugging. Both of these libraries include built-in support for debugging. Dynamic XHTML can be extremely difficult to debug. Often, the bugs that you (or your users) find are the results of a badly implemented feature in a particular version of a particular browser on a particular platform. Fortunately, this situation is improving almost daily, as the browsers' support for advanced features of the DOM and CSS2 improves.
Sadly, however, DXHTML suffers from mediocre error reporting under Internet Explorer, making it nearly impossible to use even IE's verbose error messages reliably. On the other hand, Mozilla has a wide range of tools that provide excellent and powerful debugging capabilities. From the Venkman JavaScript debugger to the DOM Inspector, practically every aspect of the DXHTML environment can be inspected and manipulated. For those on other browser platforms, a common debugging aid is to use a layer containing a Third-Party SolutionsPHP 3 provides a remote debugging service, and Zend provides similar tools that may be used as add-ons for PHP 4 in addition to third party products such as DBG and the Advanced PHP Debugger. NuSphere's PHPEd is a Windows editor that supports PHP's remote debugging and can synchronize error reports with the actual code in the editor. The popular Apache module mod_perl embeds a Perl interpreter directly into the Web server, offering superior performance to the traditional CGI approach. A popular and useful CPAN library for debugging mod_perl applications is Data::Dumper, which can dump arbitrary data structures for offline perusal. The mod_perl component is also the foundation for Mason, a component architecture for Web applications that has many debugging abilities of its own. As for Java, a wide variety of tools and architectural specifications are available, from debugging support in editors and IDEs such as JBuilder or WebSphere, to log4j, which provides a robust and sophisticated logging service for the Jakarta suite. Test harness and logging software such as that from Identify (formerly Mutek) can also aid in tracking down bugs in sophisticated Java and .Net Web applications. Many of these debugging tools are available free of charge. You can find more information and URLs for each in the sidebar, "Web Debugging Tools." So go forth, and sin no more. If you can't write code that works right the first time, at least aim to write code that's easy to fix.
Steven is CTO of Hesketh, a Web solutions vendor based in Raleigh, NC. He can be reached at schampeo@hesketh.com.
|
|
|||||||||||||||||||||||||||||
|
|
|
|