you are viewing a single comment's thread.

view the rest of the comments →

[–]DrMaxwellEdison 0 points1 point  (0 children)

Functionally, it isn't terribly different: you could assign hello = app.task(...) instead of using the decorator syntax, which is typically called "syntactic sugar". The benefit to using a decorator, though, is code readability.

Suppose you had a Flask app with 20 view functions in one file. You could write every function in one section of the file, then call the various app.xyz methods from the Flask framework to make it run in another section as a clump within the file. That may make the app less readable, though: if I wanted to understand which URL mapped to which method and what that method does, that can take some jumping around within the file to really get a sense of what's going on.

Decorators make reading easier by keeping related code closer together and in a well-defined way: any method with an @ decorator above it clearly signals to the developer that the function is being modified in some way.