Metadata/Annotations

Monkey Forums/Monkey Programming/Metadata/Annotations

Samah(Posted 2012) [#1]
Now that we have reflection, could we get metadata/annotations?

Something like:

[monkeycode]Class Foo
Field bar:String {hello="world", answer=42}
End

Local fooclass:ClassInfo = GetClass("Foo")
Local barfield:FieldInfo = fooclass.GetField("bar")
Print barfield.GetMetadata("hello") ' prints "world"
Print barfield.GetMetadata("answer") ' prints 42[/monkeycode]


Samah(Posted 2012) [#2]
I'm bumping this because I think it would be very easy to implement and very useful for libraries to interface with user code. You can just ignore metadata at compilation if you're not importing reflection.


ziggy(Posted 2012) [#3]
I'm with Samah. This would be ultra useful to implement serialization atributes for class fields (to name something where this could be definitively useful).


Tibit(Posted 2012) [#4]
I like it.

Do you have more examples of good uses (just curious)?


Nobuyuki(Posted 2012) [#5]
annotations could be implemented similarly to the VB.net syntax -- three quote marks. IDE's such as Jungle could easily extend their autosuggest features with such metadata, although they don't need official language extensions to do this if it is a comment.

Having metadata useful for getting back from reflection, though, would require extending the language, but I'd hope that rather than complicating the syntax even more with specific circumstances, that data could still be in some sort of specially formatted comment. The fact that VB.NET has separate syntaxes for both attributes and xml comments, the latter of which are what is required for IntelliSense to provide helpful documentation, is annoying to say the least -- It would be nice for us to adopt the syntax of one or the other to keep curly braces from leaking too much into the language


Samah(Posted 2012) [#6]
My example was based on the syntax from blitzmax. I don't understand this "leaking into the language" thing... You make it sound like braces are bad.

As for three quotes, comments are comments. It should be up to the IDE developers to update their software for the language. Otherwise you become Java that focuses 90% on backward compatibility and 10% on actual language improvements.


Nobuyuki(Posted 2012) [#7]
I suppose that since angle brackets are already used for generics, that it would be confusing (and perhaps difficult to read/implement/parse) to also use them for Attributes and Metadata. I'm hoping though that they can be given some sort of syntax which "feels" consistent with the language and doesn't pull anyone out of it. If BMax had that behavior with curly braces then I guess I don't have a problem with Monkey having it.

I'm assuming there'd be no strict way to declare stuff in metadata. The idea then would be that if it also served as a way to set Attributes, to somehow avoid scope conflicts with the built-in ones that Monkey could have to mark stuff as serializable, or to give fields descriptions/categories/whatever.