Boost logo

Boost :

From: Daniel Walker (daniel.j.walker_at_[hidden])
Date: 2006-04-24 12:47:12


On 4/24/06, Thorsten Ottosen <thorsten.ottosen_at_[hidden]> wrote:
> Daniel Walker wrote:
> > On 4/23/06, Peter Dimov <pdimov_at_[hidden]> wrote:
> >
> >>Daniel Walker wrote:
> >>
> >>>On 4/23/06, Thorsten Ottosen <thorsten.ottosen_at_[hidden]> wrote:
>
> >>>>Ok, why is that exception better than the one I generate if I don't
> >>>>meet the tag I expect, of if the contents of a tag is not of the
> >>>>type I expect?
> >>>
> >>>Well, you don't have to write C++ code to check if the tag/content is
> >>>what you expect. You declare the acceptable content (tags,
> >>>attribute/values, branch structures/sub-trees, etc) for your config
> >>>file in a schema, and the parser determines whether or not the XML
> >>>file conforms to the format declared in the schema.
>
> >>I wouldn't omit the checks in the code, even when using a validating parser.
> >>When the schema and the program logic disagree, the program logic "wins". Or
> >>crashes. Either way, the schema loses. :-)
> >
> >
> > Good point about crashes. It is still possible to write programs that
> > crash even when using a schema. There is no silver bullet. Whether or
> > not you want to double check the parser/scheme is the same sort of
> > decision as whether or not you define NDEBUG in a released/deployed
> > system. Sure, the asserts are still useful, but do you really need the
> > extra check? The answer probably depends on the specific circumstances
> > and is somewhat a matter of taste. I think the more common case is
> > that you forget to manually check a constraint on the XML in your
> > code, in which case you would be glad if you had a validating parser.
>
> At least for my code, a crash is not acceptable compared to a nice popup
> message: "Error in xml-file: foo";

Me too. I've just been trying to say that your code is more likely to
crash without validation than with because there's more opportunity
for human error if you're solely relying on hand written, ad hoc error
checking of the XML. So, if crashes are unacceptable, I'd highly
recommend a validating parser... though apparently it's not currently
necessary for property_tree or Boost.Serialization.

Daniel Walker


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk