PDA

View Full Version : Annotations used in JADE



Ryan
03-06-2008, 11:40 PM
Hello,
I was wondering about the annotations I so frequently see in the JADE code examples. I don't really know a whole lot about annotations, but from what I understand, they don't normally define behaviour or variables...

Do you use a special library or framework to make them do something useful? Or are you just accessing them reflexively at runtime?

Thanks.

beam
03-07-2008, 04:56 AM
They're Javadoc strings. They're inside comments, and a documentation scanner reads then when it is automatically generating documentation based on those little directives in the code.

Ryan
03-07-2008, 06:09 AM
These aren't in comments.

See http://www.adom.de/blog/2008/03/06/tribute-to-a-hero/#more-26

macias
03-07-2008, 08:03 AM
Annotations in Java (Attributes in .NET) are a way to introduce one aspect of introspective programming. They allow a programmer to attach a bit of information to the class/constructor/method/(property in .NET)/etc. With such an information and reflection mechanism you can scan for classes/methods/etc. in "current context" (please let me generalise. Java and .NET are roughly the same <don't flame PLEASE>) that follow particular pattern e.g. are stamped with annotation of type A and collect them to use the information afterwards.

It provides you the ability to extend easily: you install new lib with new classes stamped (annotated/attributed) and you main "program" sees them at no cost at all (supposing it is done well).

adom-admin
03-07-2008, 08:14 AM
Hello,
I was wondering about the annotations I so frequently see in the JADE code examples. I don't really know a whole lot about annotations, but from what I understand, they don't normally define behaviour or variables...

Do you use a special library or framework to make them do something useful? Or are you just accessing them reflexively at runtime?

Thanks.

Actually JADE does a lot of reflection to analyze objects and classes both during startup and while running the game. The annotations are used in many places all over the game to fine-tune the specific behaviour of items, monsters and the way the environment interacts with them.

Technically annotations yield meta-data that (depending on the way the specific annotation is defined) is available at compile-time or runtime. JADE uses lots of runtime metadata. Since annotations can take various parameters I use that feature intensively to fine-tune behaviour.

See the following links for more technical information (you need to understand Java):

http://java.sun.com/docs/books/tutorial/java/javaOO/annotations.html
http://java.sun.com/j2se/1.5.0/docs/guide/language/annotations.html
http://en.wikipedia.org/wiki/Java_annotation

Ryan
03-07-2008, 12:41 PM
Thanks.

(By the way, I already knew all that stuff about how the annotations are used in general, I was looking for how they're used in JADE specifically.)

Anfeir
03-07-2008, 03:57 PM
Thanks.

(By the way, I already knew all that stuff about how the annotations are used in general, I was looking for how they're used in JADE specifically.)

Specifically, you can see some of it on the code screenshots.
Isn't it enough to get the idea? :)

aran
03-07-2008, 08:24 PM
What is the advantage of using all these annotations instead of just abstracting your classes further and using XML for the specifics? I can't imagine that the "annotation style" used in Jade allows much configurability to the end-user who may want to mod. It also makes the code significantly more concrete and dramatically increases the number of classes in the system.

Epythic
03-08-2008, 06:36 PM
What is the advantage of using all these annotations

As far as I see it:


Readability + Ease of coding (e.g. you can use the auto completion features of the IDE).
Reflection (http://en.wikipedia.org/wiki/Reflection_%28computer_science%29#Java) is a nice thing too, by the way.
You have integrated type safety (for example you can't pass 123 to the Frequency annotation, instead of something like Rarity.RARE)
Possibly performance (XML is sloooow)
Writing XML is not fun. Having more classes isn't necessarily bad.