5 Comments
User's avatar
Mike C's avatar

For a relative beginner like I am (I am a student...not a professional software engineer), this article is truly a blessing. It took the rather confusing OOP subject of class methods and made it straight forward for me to get to a first gut-level understanding. I also celebrate the real-world example pulled from a professional Python space, succinct conclusions, and the resource section. Thank you, Eric.

Expand full comment
Eric Matthes's avatar

Thank you, that's great feedback. It's always a bit of a challenge figuring out how to balance the need for simplicity in a core example, with the need to tie in to the complexity of real-world projects and work.

I'm glad this was helpful to you, and I imagine you speak for a number of other readers as well. :)

Expand full comment
Rogerio Moraes de Carvalho's avatar

If I'm not wrong, languages like C# and Java treat static methods and class methods as the same concept. In that languages, static or class methods doesn't have access to instance fields (attributes), but can or cannot access class members. Do you know what was the motivation to differentiate static and class methods in Python?

Expand full comment
Rogerio Moraes de Carvalho's avatar

Eric, I post the comment before reading your note 2, that clarifies exactly my suggestion of precision. Follow your note: "To clarify, the code shown here counts how many instances have been created. To clarify, the code shown here counts how many instances have been created. It doesn’t track deletions, and it doesn’t actively count the number of instances in memory."

Expand full comment
Rogerio Moraes de Carvalho's avatar

Eric, note the following text fragment: "Here, we use cls.num_trees to compose a single sentence informing people how many trees have been added to the collection."

I think that it is more precise to say that you used cls.num_trees to compose a single sentence informing people how many trees was created from BonsaiTree class. The collection (list) referenced by "trees" variable have no direct relation with the instances. You can create an instance and not neccessarely append to the "trees" list.

Expand full comment