Hacker News new | ask | show | jobs
by devxpy 2735 days ago
Well, You'll be happy to know that a decorator is literally just a function that takes another function as its first argument.

    @app.route(...)
    def login():
        ...


Is literally the same thing as -

    def login():
        ...

    login = app.route(login, ...)

Hopefully that clears up the air a bit?
1 comments

It clears it up but personally, I'd rather just write `app.route(login, ...)`. Isn't a lot clearer to use more conventional language features? What exactly is this buying me?

I don't know if me saying 'Just, why?' is a good enough reason to throw my arms up and say it's an idea I'm not a fan of. I'm willing to say that it's a rather subjective attitude.

I guess my retort is that, it's far more confusing to have that syntax, then explain what it meant, when I could've just used the conventional syntax.

It's not like it's offering me something substantially simpler. For example, the spread operator that was introduced. It actually allows you to write clearer JavaScript code. This syntax isn't intuitively clear like the rest operator is.