Developers > Programming > Programming Best Practices

Programming Best Practices

The following suggestions will produce ExSite DCDs that are interoperable, extensible, and which make fullest use of the ExSite framework.

use Modules::BaseDCD
The BaseDCD module provides important functionality for modules to inherit, which ExSite tries to use, even if you don't invoke them explicitly.

use ExSite::Input
This enables sharing of STDIN data by the kernel and different modules, and prevents one DCD from gobbling the STDIN data that may have been intended for a different DCD. Note that this is done implicitly by Modules::BaseDCD::read(); modules that inherit from BaseDCD will find all GET and POST input preloaded into the {input} attribute of the DCD object.

use $this->link() to generate recursive link URLs
This makes some more advanced plug-in features accessible to your module, such as website services, and AJAX content handling. It also allows you to retain module state in your URLs, since any QUERY_STRING parameter that you set will persist while you remain on the same page.
 
avoid parameters with leading underscores in their names
ExSite presumes that parameters with leading underscores are for system use only, and may interfere with your parameters if you do not follow this convention.

use command-driven logic, if appropriate
This allows you to modularize the user functions, which makes it easier to handle security and access control, and extend your feature set later.

For example, use a uniquely-named command parameter, such as mycmd and set it to the various module functions, eg.

page.cgi?_id=123&mycmd=report
Other parameters needed by each specific functions can also be included, of course.
 
use URL-encoding in DCD option strings
For DCDs that accept parameters in their option strings, use URL-encoding to separate the parameters, just as you would for a QUERY_STRING. This makes it easier to interchange/interleave hard-coded parameters and dynamic parameters, and makes it easier to work with AJAX methods for fetching and inlining content dynamically. For example:
<!--&Module(x=1&y=6&fcmd=start)-->
enclose your module content in DIVs, if appropriate
Give the div a class name the same as the module, eg.
<div class="MyModule">
...
</div>
This makes it easier to apply module-specific CSS style controls, if the site wants them, eg.
/* MyModule text should be small and green */
div.MyModule p { font-size:9pt; color:#009900; }


Topics