Skip to main content

Attributes, Annotations & Decorators

This section is focused on specific examples (like the Deprecated/Obsolete) and how to create your own Attributes, Annotations or Decorators.

For Class Specific Annotations/Decorators like "Override", "Staticmethod" and so on, check the Class Section.

C

// TODO

More Info:

Back to top

C++ (Cpp)

// ------------------------------------
// Deprecated Attribute (since C++14)
// ------------------------------------

// Options:
// [[deprecated]]
// [[deprecated( string message )]]

// Function example
[[deprecated]]
void my_function(void)
{
// ...
}

// Class example
class [[deprecated("Use another class. This one will be removed next version")]] Myclass
{
// ...
};
// ------------------------------------
// Custom Attributes
// ------------------------------------

// Standard C++ Doesnt Support Custom Attributes yet

More Info:

Back to top

C# (Csharp)

// ------------------------------------
// Obsolete Attribute
// ------------------------------------

//[Obsolete]
[Obsolete]
public void MyFunction()
{
// ...
}

//[Obsolete(string message)]
[Obsolete("Use another class. This one will be removed next version")]
public class MyClass
{
//...
}

//[Obsolete(string message, bool error)] (error == true means compilation error instead of warning)
[Obsolete("Use another class. This one wont compile", true)]
public class MyClass
{
//...
}
// TODO: Others Standard Attributes Examples
// ------------------------------------
// Custom Attributes
// ------------------------------------

// TODO: Custom Attribute Creation Example

Back to top

Java

// ------------------------------------
// @Deprecated Annotation
// ------------------------------------

// The deprecated message can be documented in the Javadoc @deprecated tag.

/*
* @deprecated Use another method
*/
@Deprecated
public void MyMethod()
{
// ...
}
// TODO: Others Standard Annotations Examples
// ------------------------------------
// Custom Annotation
// ------------------------------------

// TODO: Custom Annotation Creation Example

More Info:

Back to top

Rust

// TODO

Back to top

Go

// TODO

Back to top

Javascript

// Decorators are still an experimental feature

// There is a workaround package: https://www.npmjs.com/package/depd

Back to top

Typescript

// Decorators are still an experimental feature

// There is a workaround package: https://www.npmjs.com/package/depd

Back to top

Python

# ------------------------------------
# Deprecated Decorator
# ------------------------------------

# from the lib https://pypi.org/project/Deprecated/

from deprecated import deprecated

@deprecated(version='1.2.1', reason="You should use another function")
def some_old_function(x, y):
return x + y


class SomeClass(object):
@deprecated(version='1.3.0', reason="This method is deprecated")
def some_old_method(self, x, y):
return x + y
# ------------------------------------
# Custom Decorator
# ------------------------------------

# TODO: Custom Decorator Creation Example

Back to top