Avoiding Glue-Code by using Tags

General discussion about Cobra. Releases and general news will also be posted here.
Feel free to ask questions or just say "Hello".

Avoiding Glue-Code by using Tags

Postby Thorsten » Fri Feb 29, 2008 5:25 pm

Cobra sounds very interesting and I would like to give my 5 cent on creating a new OO language. I am developing software since 27 years, so I have some experience. What I always stumble over during software development is object serialization and object communication - which is basically the same. You often write glue-code to copy the values of members of class A to class B or write code to store or read values of members in/from streams.

This is an annoying and stupid task, ending in many lines of code like:

It is also error-prone if you add a new member and forget to write and/or read it.

To solve this issue, one solution could be to "tag" members of classes. For instance, if I could tag all members which shall be serialized to a stream as "streamable", then an interface could enumerate all streamable members and write/read them to/from streams automatically without writing specialized code. XML streams would be a good choice, but it should not be limited to this.

The same could be done to exchange data between two classes, for example an Address class (with a person's address information) and a generic record class of a database driver, which provides fields of a table as an array. In this case the tag could be "db" for database. Maybe it could be even solved by the same "streamable" tag, using a different underlying stream class.

It would also make sense that multiple tags can be assigned to a single member or property and when a tag could hold a value, e.g. tag "size = 80" to specify the maximum allowed size of a string which would instruct a GUI class that the edit control associated with a member may have an input of max. 80 characters.

Of course such generic things wouldn't always work, for example if streaming would involve that multiple members are written as a single date. In this case it should be possible to overload the method which does the "automagic", so the members which can not be handled automatically are not tagged and handled by extra code.

Please let me know if this is something which could be implemented into Cobra.

Posts: 2

Re: Avoiding Glue-Code by using Tags

Postby Charles » Fri Feb 29, 2008 8:44 pm

You'll be glad to know that Cobra has "tags". They are called "attributes" and are actually a feature of .NET/Mono. You can inspect attributes at run-time and take actions based on them. See

If you search the web for "C# attributes" or "Visual Basic attributes" you'll be able to leverage that information directly.

Also, check out the 4.5 star book "Applied .NET Attributes".

.NET also has a definite approach to serialization that looks pretty easy to use and can be customized. Again if you search the web for "C# serialization" or "Visual Basic serialization" you'll find what you need.

So the two things you are looking for are already addressed by the platform that I chose to start Cobra on.
Posts: 2513
Location: Los Angeles, CA

Return to Discussion

Who is online

Users browsing this forum: No registered users and 7 guests