I understand that in Solidity if a function has a modifier, this modifier runs first, prior the the logic within the function running. This is done for checks of ownership, checks of state, etc.
In Python, the concept of decorators seems very similar—a decorator replaces the decorated function with a new function that accepts the same arguments and returns whatever the decorated function was supposed to return, while also doing some extra processing.
In terms of what goes on behind the scenes, I know that in Python, the following are equivalent:
@clock
def factorial(n):
return 1 if n < 2 else n*factorial(n-1)
and
def factorial(n):
return 1 if n < 2 else n*factorial(n-1)
factorial = clock(factorial)
From my understanding, the following are equivalent in Solidity:
function startSale() notCanceled {
...
}
and
function startSale() {
notCanceled()
...
}
My question is, are these two features meant to perform roughly the same task? When learning solidity, is comparing a decorator to a modifier a fair comparison to make? If so, why? If not, why not?