Load Delegation

Trans <[email protected]>
Newsgroups gmane.text.yaml.general
Message-ID <[email protected]>
I'd like to get some feedback on an idea I have to implementing a YAML 
parser.

I was thinking that instead of instantiating the objects to native types 
directly, it could instantiate a delegator around the native type. e.g. 
instead of (in Ruby code):

     YAML.load('--- "string"') => "string"

It would produce

     YAML.load('--- "string"') => Y("string")

For all practical purposes Y("string") behaves just like "string".

The main reason for doing this is because of immutable types. Immutable 
types are difficult to load with self-referencing anchors --indeed the only 
solution I found was to forbid it. Immutable types also might not round 
trip well, b/c they are often singleton. So if the same object comes in via 
two different tags --say a schema supports both `!foo` and 
`foo.org,2000:foo`, it is only possible to emit it with on or the other. 
There is no way to remember which it came in with. Using the delegator is 
also nice b/c schemas then don't need to specify the type-class a tag goes 
with necessarily, they can just define how to load the representation. 
Without the delegator, the schema has to provide the class so that it can 
be allocated ahead of time in case there is an anchor/reference for it.

The downside, of course, it that as close as Y("string") is to mimicking 
"string" there is always going to be a few ways in which it is not the 
same. Typically these differences don't matter. But when doing tricky 
things, in particular  meta-programming kinds of things, then it could be 
cause issues --in which case one would have to be sure to manually "unwrap" 
the delegation,

So what do you think? Is this a good idea? Or am I bat-shit crazy and just 
asking for trouble?

Thanks.

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_feb

_______________________________________________
Yaml-core mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/yaml-core
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.