From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id PAA26329; Fri, 13 Jun 2003 15:45:09 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id PAA26212 for ; Fri, 13 Jun 2003 15:45:08 +0200 (MET DST) Received: from rabelais.socialtools.net (rabelais.socialtools.net [81.2.94.243]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h5DDj7H22523 for ; Fri, 13 Jun 2003 15:45:07 +0200 (MET DST) Received: by rabelais.socialtools.net (Postfix, from userid 1000) id 63107232D8; Fri, 13 Jun 2003 14:45:07 +0100 (BST) Date: Fri, 13 Jun 2003 14:45:07 +0100 From: Benjamin Geer To: caml-list@inria.fr Subject: Re: [Caml-list] HTTP-server written in ocaml Message-ID: <20030613134507.GC4754@socialtools.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.3.28i X-Spam: no; 0.00; caml-list:01 frameworks:01 templating:01 jakarta:01 velocity's:99 camlp:01 -like:01 syntaxes:01 model:01 implemented:01 reuse:01 ocaml:01 caml:01 readable:01 concise:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Jurjen Stellingwerff wrote: > More info on: http://camlserv.sf.net I've worked on several web application frameworks and templating systems (in languages other than Caml). After a brief look at Camlserv, I have a few suggestions. 1. A templating system can be useful for generating many things besides HTML. For example, I've used templating systems to generate email (automated replies), SQL, other sorts of program source code, configuration files, etc. Therefore, if you want to provide a templating system, I'd recommend making it a general-purpose one, not tied to the HTTP server or to HTML. Two examples of such a system (in Java) are Velocity: http://jakarta.apache.org/velocity and FreeMarker (I was the original author): http://www.freemarker.org 2. A templating system, when used to generate web pages, should have a syntax which web designers will find easy to use. The XML-like syntax you propose is, in my view, rather cumbersome. Many web designers are familiar with JavaScript, whose syntax is more concise and readable. Here again, I'd recommend looking at Velocity's syntax. Your conditional syntax looks like this: .... .... Try reading that out loud: "When test equals user is logged in...". It doesn't sound like what it means. Web designers will find this confusing. Now compare the syntax for a conditional in Velocity: #if ($user_is_logged_in) ... #else ... #end If you read that out loud, you get: "If user is logged in...". It sounds like what it means. Cheetah (http://www.cheetahtemplate.org), a Python-based templating system, has also adopted this syntax. You might consider using a camlp4-like approach, to allow your template engine to use different syntaxes. 3. I notice that you have some syntax for connecting to a database. It appears to be very MySQL-specific. Also, your mechanism allows people to include SQL in their templates. This is generally considered to be poor design. Most web application frameworks follow the model-view-controller approach, in which templates contain *only* presentation logic (e.g. HTML, and any control structures needed for controlling the way data is presented). A template gets data from a 'model', which is simply a data structure provided by another module or program. That data could come from a relational database, from files, from LDAP, or from anywhere else. The 'controller' is a module which, given a request, decides which model and view should be used to handle the request. This allows you to change the way the model is implemented without changing the presentation layer (the 'view'). It also means that templates are not cluttered with data access syntax (e.g. SQL); this makes life easier for web designers. Most importantly, this approach allows for code reuse. View components can be reused with many different models. For example, you might create a general-purpose tabular HTML view, with typical features such as allowing the user to sort on any column by clicking on the column's heading. This view could then be used with models containing data from many different sources, including databases. Similarly, model components can be reused with many different views. You might have different versions of your web site for different users, e.g. a printable version, or a low-graphics version for disabled users. More generally, a model describing a document could be rendered by an HTML view, a LaTeX view, a plain-text view, etc. Hope this helps, Benjamin ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners