Scripting and XML

Simeon Simeonov simeons at allaire.com
Mon Oct 20 00:58:05 BST 1997


Disclaimer: I'm new to SGML and XML...

>So, major code reuse akin to headers in C/C++ is possible if ugly. But
>minor recycing of code is impossible for now. MSIE4 introduces a new form
>of script object handling, "scriptlets", which addresses this problem to
>some extent, but any useful script component would need to be extended
>to fit any given situation - the same problem which drives OOA&D/OOP -
>so it has yet to be seen how useful this scriptlet idea will be.


I think there is a method for code reuse that is (a) more flexible than
includes, (b) as powerful as object-based reuse (scriptlets), and (c) a lot
closer to the syntax of generalized markup. Essentially, it involves reuse
through flexible tag structures. I'd like to start with an example from my
domain of expertise--web applications. (Credit goes to Len Bullard because
the example emerged from an offline discussion about XML Scripting...)
Consider the following piece of code (ignore actual tag syntax, etc.):

<T1 A1=V1 ...>
<SCRIPT>
    result = process(argument)
    Write(result)
    ...
</SCRIPT>
<T2 A2=V2 ...>

What do you do if you decide that this piece of code is useful and should be
reused? Includes won't work well, because the result of processing depends
on the value of argument. Scripts will force you to modify the code before
reuse, e.g.,

<SCRIPT>
    Write("<T1 A1=V1 ...>")
    result = process(argument)
    Write(result)
    Write("<T2 A2=V2 ...>")
</SCRIPT>

Then you'll put the body of the SCRIPT tag in a procedure/function... That's
somewhat unpleasant. Code reuse shouldn't mean code re-write! What is really
needed is a mechanism which allows (a) automatic reuse of tags *and* scripts
with little code changes, and (b) safe argument passing.

The language that I am working on (CFML - the Cold Fusion Markup Language
from Allaire Corp.) uses a flexible tag-based mechanism for this. The
example code needs to modified only slightly to indicate which variables are
inputs and then needs to be placed in a separate file.

File DoSomething.cfm:
<T1 A1=V1 ...>
<SCRIPT>
    result = process(Arguments.argument)
    Write(result)
    ...
</SCRIPT>
<T2 A2=V2 ...>

It can then be invoked in one of three ways:

<CF_DoSomething Argument=Value>
<CFMODULE Name="ArbitrarilyComplex.DottedNameHere.MuchLikeJava.DoSomething"
Argument=Value>
<CFMODULE Template="SomethingLikeARelativePath/DoSomething" Argument=Value>

(Please, ignore the exact details of the naming scheme.) I think that CFML's
approach is (a) significantly better than includes, (b) as powerful as
scriptlets, and (c) a lot more markup friendly. (In general, CFML is quite
tag-friendly; the language uses tags for flow-control, expression
evaluation, etc.) Also, code reuse involves less code modification than
other approaches that I know of.

Don't get me wrong. This is not the exact syntax I am recommending for XML!
I just wanted to point out one case where scripting and code reuse have been
successfully addressed with markup. There are tens of thousands of CFML
developers that strongly prefer this approach to a stew of markup and
script. In a markup language shouldn't the unit of code reuse be a tag???

I hope I have not bored you with the rather long message... If you'd like to
look at CFML and the Cold Fusion Application Server, check out
http://www.allaire.com.

Regards,

Simeon Simeonov
Language Architect
Allaire Corp.
simeons at allaire.com







xml-dev: A list for W3C XML Developers. To post, mailto:xml-dev at ic.ac.uk
Archived as: http://www.lists.ic.ac.uk/hypermail/xml-dev/
To (un)subscribe, mailto:majordomo at ic.ac.uk the following message;
(un)subscribe xml-dev
To subscribe to the digests, mailto:majordomo at ic.ac.uk the following message;
subscribe xml-dev-digest
List coordinator, Henry Rzepa (mailto:rzepa at ic.ac.uk)




More information about the Xml-dev mailing list