Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion bot/resources/tags/decorators.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,23 @@ embed:
---
A decorator is a function that modifies another function.

Consider the following example of a timer decorator:
Given the decorator
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather we'd give the timer example.
decorators are not an easy topic for beginners, and if we're explaining how interpreters translate the syntax & how it executes them, we might as well keep the same example for consistency and also to avoid confusing beginners.

So you would demo the equivalent syntaxes, then you would give the execute example of both of them to demonstrate it even further

```py
def deco(f):
...
```
then the following constructs are functionally equivalent
```py
def tmp_fun():
...
fun = deco(tmp_fun)

@deco
def fun():
...
```

As an example consider the following example of a timer decorator:
```py
>>> import time
>>> def timer(f):
Expand Down