To close this manual, I would like to give a few words of advice on how I
think Draco should be used. Draco has intentionally been kept flexible,
because I realize that no single programming paradigm can be right for all
situations. However, this does not propagate software anarchy in the spirit
of PERL's ``There's more than one way to do it''. In this respect, Draco's
motto is closer to Python's ``There should be one - and preferably only one
- obvious way to do it.''
Below are some rules of thumb that I have found useful. This is by no means
authorative or anything, just some well-intentioned sharing of ideas.
- Use files and directories to structure your application:
- Group similar pages in their own directory. This way, related handler
code will be in a single file.
- Use different files for different pages. Don't use a single main page
that includes its body from another file as specified by a parameter.
Instead, use multiple files that each include a common header and footer.
This is much better suited to Draco because it allows you to have separate
handler function for separate pages.
- Don't try to cram multiple pages in a single template. This can happen
for example when you want to handle special cases like when you found no
data or when an unexpected situation has occurred. Instead, use http
redirects to redirect from one template to the other.
- Put as little code as possible in the templates. Ideally, templates
only contain code to format end results. All processing should be done in a
handler.
- Make liberal use of the session and other namespaces. Use the methods
update() and clear() to transfer and clear entire
namespaces with a single function.
- Use Draco's Form class to parse form input. When an error
occurs, put the unprocessed variables in the session using a single
update() call. Use an http redirect to go back to the form and
there, register a FormRewriter instance to plug back the variables
in the form.
- Put files that are related to your web application but should not be
public under the document root in a __private__ directory.
This way you keep your application nicely in a single place.
- Use the builtin task scheduler to perform expiry tasks. If exact
timing is important, use cron to fire it up.
- Use the childStart() event to register global variables that
you are going to use in your web application. Use requestStart()
and configChanged() to keep these variables up to date.