In Python, this code is an example of decorators:

def main_func():
    # Do stuff

When main_func is called, it will call decorator_func with main_func as the only argument. It will then call the returned function* instead of main_func with the arguments provided.

*A decorator doesn't have to return a function, but that doesn't really matter.

Read this for more info on Python decorators.

Anyway, as you can see above, Python uses @ and then the decorator function name before the main function definition. Are there any other syntax options for implementing this? And what are their advantages and disadvantages?


1 Answer 1


Rust/C# Attributes

Rust and C# use similar syntax for their "attribute" feature, which is closer in functionality to Java's annotations but is used in the same manner as decorators syntactically.


fn test_foo() {
    /* ... */

(Rust also allows attributes to be applied to the whole module, using this syntax:)

#![crate_type = "lib"]


public class SampleClass
    // ...

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .