C# and Java has code attribute and code annotation. I don't know about other languages, but I know the code annotation feature is used to expand language itself.

I knew what it is, but I want to know how it developed over time. I want to know its history. How it demanded and how it implemented. Is this possible to implement this in kind of concept on LISP, Smalltalk or C++?

And is there a general term to call the concept of annotation?

  • 6
    The term you are looking for is metaprogramming, I think.
    – Michael K
    Mar 27, 2012 at 14:31
  • 2
    I have read somewhere that annotations biggest discovery(or improvement) in java in the last 10 years. XML was simply over used for anything and everything, with the entry of annotations its usage might go down.
    – ManuPK
    Mar 27, 2012 at 14:45
  • Metaprogramming and annotations are really rather opposites: metaprogramming lets do things (mostly arbitrary computations) at compile time that are normally associated with execution time. Annotations let you do things normally associated with compiling (e.g., affecting code generation) at run time instead. Mar 27, 2012 at 16:15
  • @JerryCoffin, I don't think it's that simple. For example Reflection.Emit certainly is metaprogramming, but it lets you do things (define types and methods) and runtime that are usually done at compile time.
    – svick
    Mar 27, 2012 at 16:25
  • @svick: What definition make it "certainly" metaprogramming? Mar 27, 2012 at 16:26

2 Answers 2


This usually is related to reflection, since reflection is the only way to look at attributes or annotations (depending on the language). So it might be possible for LISP but not for C++.

Also, annotations are only a series of name/values that are tagged to a specific class, method, field, etc.

So inside the meta-object that stores information about a class (ex. it's methods, fields, etc.), one needs to add another map (or list) that contains information about all the attributes an class or method contains.

Obviously, if you don't know what a meta-object is, you should study meta-programming a little, particularly CLOS (Common Lisp Object System), that is the mother of all languages implementing metaprogramming.

  • 2
    Annotation are not all runtime. Java have source-only annotation. They can be traced back to pre-processors.
    – J-16 SDiZ
    Mar 27, 2012 at 15:06
  • Agreed and there are some post-compilation tools that use Attributes in C# to modify the compiled code (PostSharp is an example). Mar 27, 2012 at 15:32

I can't speak much for Java Annotations but C# Attributes were introduced in the first version of .NET when Microsoft was pushing Web Services heavily. Attributes allow you to provide metadata about your code (or metaprogramming as it were) that the framework can look at and use to enhance your code. For instance in .NET 1, you could use the WebMethod attribute to tell the framework that you want to expose a method over a Web Service. The framework would handle the rest.

In C++ people use Preprocessor Directives and Macros to perform Metaprogramming. Other languages (like Lisp and Boo) have Metaprogramming built into the language. This article on wikipedia provides a great starting point on the topic.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.