[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Scripting and XML
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@a... xml-dev: A list for W3C XML Developers. To post, mailto:xml-dev@i... Archived as: http://www.lists.ic.ac.uk/hypermail/xml-dev/ To (un)subscribe, mailto:majordomo@i... the following message; (un)subscribe xml-dev To subscribe to the digests, mailto:majordomo@i... the following message; subscribe xml-dev-digest List coordinator, Henry Rzepa (mailto:rzepa@i...)
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|