Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

Due to the requirement of a project we had to develop a data interchange format with a built in data types. The format served the purpose well in the scope of that project. But I was thinking that does it have any advantages of having a built-in type system (int, long, bool, string etc.) in a more general scope of data interchanging?

Take XML as an example. It has been serving the purpose very well, but if XML would have a built-in data type system (forget about dtd/xml schema), would that be of any extra advantage than its currently having? e.g, we generally use xml for serialization, during the operation if we would be able to store the datatype along with the data, would that be more helpful?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

There are two distinct ideas here.

The first idea is that the format could have types. XML doesn't; XDR and bencoding do. As you are evidently aware, XML Schema adds data types to XML; this is evidently something that many people have found lacking in XML. Moreover, if you have typed data, then if you're using an untyped format, then at some point, you are mapping between typed and untyped forms, and vice versa, in which case you're essentially imposing your own type system. You might as well have a type system in the format to start with.

The second idea is that the format could embed types in the data. XML can't, because it doesn't have types. XDR doesn't, bencoding does. There are many other examples on either side. The tradeoff is simple: formats which don't embed the types can be more compact, but formats which do can do a better job of detecting mistakes. A very common kind of mistake is a format change: you write some data in version N of the format, and read it with version N+M of the format; the more information about type and structure you embed, the better chance you have of detecting this rather than reading garbage. Data with embedded types can also be processed without knowing about its structure (eg you translate bencoded data to JSON without knowing anything about what was in the data; you couldn't do that with XDR), but i suspect this is rarely useful in real life.

So, it's a tradeoff. If the format is for interchange of data between machines in a cluster, where they will all be running the same code, the integrity advantages of embedded types seem largely irrelevant. If it's for interchange of data between different companies, or long-term archival of data from some system, then the integrity advantage could be very valuable.

share|improve this answer
    
excellent answer, very elaborative too.. thanks a lot for your time .. –  Anindya Chatterjee May 17 '11 at 18:52
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.