The
Model-View-Controller
(MVC) pattern separates an application into three components:
- Model - maintains the state of the program, contains the data store
- View - creates a 'view', that is it transforms the model data into
a form accessible to the user
- Controller - implements a user interface that allows the user to
interact with the model
The MVC pattern is an updated version of the old adage that computer
programs come in three parts: input, processing, and output. It is a
nice way to describe the high-level architecture of an application
because Views and Models naturally separate form from
content. Separating form from content usually leads to cleaner code
and greater flexibility.
For a future web application, I am meditating on the best approach to
take for the view and model. There are two general approaches I am
looking at.
The first is a traditional perl templating scheme. The model would be
a flat file or relational database, bound to a perl program through
DBI. The view would consist of a set of template documents
that would transform data to various formats (HTML, plain text, CSV,
etc.) using, for example, Template::Toolkit.
The second approach is to build an XML application. The model stores
data in an XML format and is accessed directly, or perhaps using
XML::LibXML. The view would consist of a set of template
documents that would transform data to various formats (HTML, plain text, CSV,
etc.) using the XSLT language via, e.g., XML::LibXSLT.
I have little experience with either templating scheme, and I am
seeking advice on the pros and cons of these two approaches. I
understand that the subject of XML vs. relational databases is
contentious. Let's assume that I am comfortable implementing either
variety. and that the database will be small enough that performance
considerations will not be foremost in the design. Also, if
performance becomes a problem, I could create an XML wrapper around
DBI results. So the comparison becomes that of a perl templating
language vs. XSLT.
Some questions pertaining to the comparison are
- I'd like the code to be maintainable after I leave. Is it
reasonable to expect novice programmers to be able to learn to manipulate
and modify Template Toolkit templates? What about XSLT?
- XSLT seems like a cool language in theory, but how is it in
practice? Does it DWIM, or is it fussy and frustrating?
- One aspect of XML/XSLT I like is that they are language
neutral. Once the docs and templates are written, they can be
processed in any number of languages: Perl, Java, C, C++, Python,
etc. On the other hand, Perl and associated templating systems are in
widespread use and not going away any time soon, so perhaps language
neutrality is not so important?
- Associated with XSLT is XSL-FO, an XML formatting language. Is
XSL-FO commonly used as part of the transformation process?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.