logoalt Hacker News

Sohcahtoa8204/23/20250 repliesview on HN

I wonder if the people that struggle with decorators have a fundamental struggle with seeing functions as objects that can be redefined or modified.

A decorator basically just does something when a function is defined. They can be used to do something when a function is defined (such as register the function with a list of functions), or modify the function's behavior to do something before and/or after the function is called (like create a poor man's profiling by timing the function call).

You can do all that without decorators, of course, but the code looks a lot cleaner with them.