sa2c / python-oop-novice

An introduction to object-oriented programming for Python users in research
https://sa2c.github.io/python-oop-novice/
Other
1 stars 5 forks source link

Emphasize that the decorated function is a different entity #20

Open chillenzer opened 1 year ago

chillenzer commented 1 year ago

In the Decorators chapter the first example decorates by hand and uses the same name for the original and the decorated function. This is the standard pattern from which the usefulness of decorators arises but I could imagine that it is could even be better for starters to distinguish between the two versions of the function and make the identification of the two an explicit step of the process of arising at decorators.

edbennett commented 1 year ago

Ah, I approached this from the opposite point of view—that people will understand that assigning a different thing to the same name will have created a new entity, and that providing the equivalent code that does the exact equivalent of what the decorator syntax does better illustrates that point.

Would a sentence or two in the narrative (as a callout or otherwise) achieve the same effect?

chillenzer commented 1 year ago

Well, I don't think that it's a bad approach. I personally like to look under the hood of things just like I better understand git since I know that it implements a content-addressable filesystem. From that perspective, walking through all the steps and entities involved in the process explicitly and having the maximal control and separation of steps involved would likely bring a benefit to me. But it would be significantly more verbose and it would make the transition to the special case that is implemented via decorators less natural. So, it's more a thought than a strong opinion.