From: why t. l. s. <yam...@wh...> - 2002-07-23 19:46:17
|
Clark C . Evans (cc...@cl...) wrote: > Second, I was thining about private types; they are in general > rather useless since you can't even match on them; !!x in a > query language isn't the same as !!x in a document. Thus, I'm > questioning if we even need private types? I didn't think private types were necessary until you suggested the new domain type standards. Now, I see a place for private types. You have described domain types as very well-defined structures. For YOD, I plan on using domain types to describe the schema for my document structure. I also find them useful because they map directly to my YOD classes. So for serialization and self-documentation, domain types make sense. But I see people-- and I'm thinking of Ruby YAML users in particular-- wanting to serialize classes quickly. Classes that may change in structure frequently. My options for them are to have them use the http://ruby.yaml.org/Object type. Or we could have them use private types. So if I have a ruby class called 'Comedian', which has a first name property and a last name property, YAML4R could swing either way: # Example One: Domain type --- #YAML:1.0 !ruby/Object:Comedian first name: Bob last name: Odenkirk # Example Two: Private type --- #YAML:1.0 !!Comedian first name: David last name: Cross First of all, I think the syntax for the second is cleaner. Now, let's consider how this is unserialized by Ruby. This is where I see the huge gain with private types. This is this meat of the discussion I think. With Example One (the domain type), the parser will attempt to construct a new Object of the 'Comedian' class. If this class is not available, the parser will be forced to throw an error, as the class is not defined anywhere. I can see cases where this is advantages. If the class isn't found, then neither are the methods of the class and everything that makes classes so wonderful. On the other hand, when Example Two is parsed, the parser will create a new class 'Comedian' descended from YAML4R::PrivateType. This class will be an object without methods or proper inheritance, a generic class with the structure supplied by the hash. Now, this may not seem useful, but think of how useful this could be when passing objects between languages which have no understanding of each other's classes. I could pass the Comedian class to Perl. Perl could correct the actor's name or something and return the Comedian class back to me with changes. To Perl it's a private type, so it's structure needs to stay intact. To Ruby it's the Comedian class, methods and all. I think this is tremendously cool and we should work to keep it. > Third, Steve says that _why has referred to "type family" as a domain; > this actually sounds like a better word than type family. Thoughts? I thought I got that from the spec. Agg! I'm reading the spec so much that it's saying things to me that it's not saying to the rest of you! _why |