Feb-23-2024, 04:25 PM
I'm not new to coding but new to Python. Decided to go through the CS50P course to get up to speed. Early on decorators were introduced which I thought was odd. I am familiar with decorators in Java/ general OOP and understand the concept but haven't really used them.
As the course is introducing them early on I assume they will be important to the work on the course. As I said, fine with the general concept but the @annotation is really causing me a problem. I understand it but I can't see why anyone would use it in production.
Maybe I am missing something but it seems to me that it totally couples the original function to the decorator. How is that good if I want to use my function in other decorators? I feel like I would never use the @ as I would be thinking about how inflexible it is. Is my OOP clean code indoctrination making me see something that isn't there?
I have tried to find an answer to this but every tutorial and article uses the same basic examples and doesn't discuss this problem. Is it a problem or not? That makes me feel like I am missing something fundamental - some big difference between my normal OOP understanding of decorators.
To hit such a mental roadblock so early on is frankly demoralising - I thought Python would be very straightforward!
Please help free my mind!
As the course is introducing them early on I assume they will be important to the work on the course. As I said, fine with the general concept but the @annotation is really causing me a problem. I understand it but I can't see why anyone would use it in production.
Maybe I am missing something but it seems to me that it totally couples the original function to the decorator. How is that good if I want to use my function in other decorators? I feel like I would never use the @ as I would be thinking about how inflexible it is. Is my OOP clean code indoctrination making me see something that isn't there?
I have tried to find an answer to this but every tutorial and article uses the same basic examples and doesn't discuss this problem. Is it a problem or not? That makes me feel like I am missing something fundamental - some big difference between my normal OOP understanding of decorators.
To hit such a mental roadblock so early on is frankly demoralising - I thought Python would be very straightforward!
Please help free my mind!