Programming Languages - Annotations
Annotations: additional / meta information
- for human: documentation
- for compilers: optimization
C++: Attributes
Since C++11.
Syntax: [[attribute-list]], where attribute-list is a comma-separated sequence of zero or more attributes.
For example:
[[deprecated]]
void Foo(int);
Java: Annotations
The at sign character (@) indicates to the compiler that what follows is an annotation.
Examples:
@Override: it tells the compiler that the child class method is overwriting its base class method.@SuppressWarnings("unchecked"): it tells the compiler to ignore the specified warning.
To declare an annotation:
public @interface Foo {
public String bar();
}
Kotlin: Annotations
annotation class Fancy
Rust: Attributes
(Examples from the official site: https://doc.rust-lang.org/reference/attributes.html)
InnerAttribute: #![ Attr ]
- if at the top level, it applies to the enclosing module or crate.
- if inside a
fn, it applies to the entire function.
// General metadata applied to the enclosing module or crate.
#![crate_type = "lib"]
OuterAttribute: #[ Attr ]: applies to the thing that follows the attribute.
#[test]
fn test_foo() {
/* ... */
}
Go: Struct Tags
Golang does not provide annotations, but you can use struct tags to store metadata.
type User struct {
Name string `json:"name"`
Password string `json:"password"`
}
Recommended Reading
SponsoredConcepts
- Overview
- Which Programming Languages To Learn
- Compile Time and Runtime
- Standard Libraries
- Build Tools
- Memory Management
- Zero Cost Abstractions
- Design Patterns
- Constructors
- Compatibility
- Closures
- Functional Programming
- Generics
- String Interning
- Coding Conventions
- Main
- Ranges
- Lambda
- Random
- IO
- Operators
- Built-in
- Constants
- Functions
- Generics
- Print
- Pointers
- Annotations
- Quotes
- Destructuring
- Generators
- Imports
- Iterators
- Testing
- Visibility
- Assignment Semantics
- Slices
- SSA
- Versus
Concurrency
Control Flow
Data Structures

