What A Great Way To Ask A Technical Question!

August 2, 2017

Browsing around to get an answer about a technical question, I stumbled unto an unusually well-structured StackOverflow question by Martineau which had a corresponding unusually helpful and thorough answer. This made me go if only my questions were this well-posed, I would’ve gotten better quality help, so allow me to share it.

Meaning of @classmethod and @staticmethod for beginner?

Could someone explain to me the meaning of @classmethod and @staticmethod in python? I need to know the difference and the meaning.

As far as I understand, @classmethod tells a class that it’s a method which should be inherited into subclasses, or… something. However, what’s the point of that? Why not just define the class method without adding @classmethod or @staticmethod or any @ definitions?

tl;dr: when should I use them, why should I use them, and how should I use them?

I’m pretty advanced with C++, so using more advanced programming concepts shouldn’t be a problem. Feel free giving me a corresponding C++ example if possible.

I feel like the question is really good because it’s structure goes like this:

Ask the question directly, following by what you want to get out of the answer.

Could someone explain to me the meaning of @classmethod and @staticmethod in python? I need to know the difference and the meaning.

Let the help know what you understand and what is your point of confusion.

As far as I understand, @classmethod tells a class that it’s a method which should be inherited into subclasses, or… something. However, what’s the point of that? Why not just define the class method without adding @classmethod or @staticmethod or any @ definitions?

Summarize.

tl;dr: when should I use them, why should I use them, and how should I use them?

Tell people your background and your preferred analogies (while subtly legitimizing yourself so that strangers on the web take your question seriously).

I’m pretty advanced with C++, so using more advanced programming concepts shouldn’t be a problem. Feel free giving me a corresponding C++ example if possible.


when should I use them, why should I use them, and how should I use them? Man that was good.

What A Great Way To Ask A Technical Question! - August 2, 2017 - Hang Lu Su