The shortcomings of above is we can’t use it directly, we have to assign it to a new varialbe, and invoke that function again

we can use @decorator to avoid change function definition or function calling, which is the benefit of using decorators

@decorator
def f2():
print("This is a function")
# with the above definition, we can call f2 directly
f2()

1549296721.0764937
This is a function

1.4 Why decorator?

originally f2 only prints “This is a function”

by adding @decorator, f2 can print its original function as well as time

We can accept the complexity in definition, but we shouldn’t accept the complexity in calling/invoking

decorator is a type of AOP (aspect oriented programming). In computing, aspect-oriented programming (AOP) is a programming paradigm that aims to increase modularity by allowing the separation of cross-cutting concerns.