|
[XQuery Talk Mailing List Archive Home] [By Date] [By Thread] [By Subject] [By Author] [Recent Entries] [Reply To This Message] Schema Typed Parameters and Return Values in Library ModulesDavid Graf david.graf at 28msec.comMon Jul 19 22:43:46 PDT 2010
Hello Everybody
At FLWOR/Zorba group, we are having a discussion about the usage of schema typed parameters and return values in the API of library modules. As you might know, the Zorba XQuery engine supports XML schema. Therefore, people like me are thinking about typing parameters and return values of functions of Zorba's library modules with schema types (with http://www.w3.org/TR/xquery/#prod-xquery-SchemaElementTest). But if parameters of functions are types with schema types, a user of the function needs to validate the data before passing it (with http://www.w3.org/TR/xquery/#doc-xquery-ValidateExpr). And to validate, the right schema needs to be imported. Therefore, some people in our group think that the validation should be done inside the modules but the module programmers. And the users should be informed with error messages if something cannot be validated.
Here is a short example:
Variante 1 (param validation by user):
Module:
declare function foo:bar($param as schema-type(aa:bb)) {
(: xquery code :)
};
User Query:
import schema namespace aa = "http://www.aa.com";
let $param := validate { <aa:bb>...</aa:bb> }
return foo:bar($param)
Variante 2 (param validation by module):
Module:
declare function foo:bar($param as elemente(aa:bb)) {
try {
let $validated := validate { $param }
return
(: xquery code :)
}
catch (err:something) {
fn:error(..., "user, your data is wrong!!")
}
};
User Query:
declare namespace david = "http://www.david.com";
foo:bar(<aa:bb>...</aa:bb>)
Personally, I think the validation of an item should be done by the creator of the item. Therefore, the parameters and the return values should be schema typed. Means, the user validates the parameters, the module programmer validates the return values. In my opinion, this brings a lot of benefits. E.g. the user of a module gets an error message in his own code if he creates a wrong item. Just type safety like in programming languages like Java. The only tiny problem is (in my opinion): almost all XQuery users are not familiar with the validation construct.
The other opinion is: The life for the module user should be made as easy as possible. Therefore, the validation of the parameters should be made by the module programmer. Of course, it easies the usage of a module a little bit. But already the bug fixing gets more complicated because the location of the bug is in the module instead in the code of the user. Therefore, programmers of modules need to give module users very specific error messages of a parameters is not correct. In my opinion, this makes the life of programmers of modules unnecessary complicated.
What do you think about this topic? What should be the best practice?
Regards,
David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://x-query.com/pipermail/talk/attachments/20100719/353edbbe/attachment.htm
|
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
|






