2

Good morning SE,

I've been wondering, now that I'm shoulder deep in Python, when it is best to not use classes in Python? Is there a particular instance or reason why classes shouldn't be utilized?

For the sake of the argument, I understand, and hope others understand, that OOP [Object Orient Programming] is directed towards utilizing classes, re-usability, checking and creating states, providing encapsulation and inheritance... But is there a reason to not do the things Python holds so dear?

Looking through some of the related questions, I noticed I'm asking the exact opposite of this one (note, I intend to ask this question because of curiosity, not with the intent to bash anyone's working methods): Why should I be using classes in Python?

SirJames
  • 387
  • 8
  • 27
  • don't use them when you don't need to, if you just need a function you don't always need a class – depperm Jul 12 '17 at 14:23
  • 2
    This is a discussion / talking point. Off topic – Lightness Races in Orbit Jul 12 '17 at 14:26
  • This is a *great* question... just not for SO. Or any SE site. But FWIW, this is pretty hotly debated in not just Python but JavaScript as well. – Jared Smith Jul 12 '17 at 14:29
  • @LightnessRacesinOrbit Ah, alright. Sorry, I thought this would be a good on-topic Python question because it would directly relate to workflows and usage. Provided, I didn't post any code... – SirJames Jul 12 '17 at 14:51
  • @depperm, that's a simple explanation and probably the most correct one. – SirJames Jul 12 '17 at 14:52
  • @JaredSmith, I guess I asked this because it seems like there might be a prime example of not utilizing classes being better or correct over using them. I hadn't realized it was a hot topic (especially since I saw no one had posted a question like this on here before). – SirJames Jul 12 '17 at 14:55
  • 1
    @SirJames: Workflows are a matter for [SoftwareEngineering.SE] but, as a discussion point, this is still better off in a chatroom tbh – Lightness Races in Orbit Jul 12 '17 at 15:18
  • 2
    _"especially since I saw no one had posted a question like this on here before"_ They have, many many times, and we keep deleting them for being off topic :) – Lightness Races in Orbit Jul 12 '17 at 15:18
  • 1
    @SirJames its a judgement call. In Python specifically classes tend to be faster than using generic data structures but are more brittle: every dev and library knows how to work with lists and dicts but custom class APIs have to be learned and re-learned when they change (and *boy* do they change). Then you get into the whole inheritance vs composition discussion. Then you get into the mutability discussion. I don't think classes add much value and rarely if ever use them, but the debate is far too nuanced to be summarized in a reasonable SO answer. – Jared Smith Jul 12 '17 at 15:25
  • Ah! That explains a lot, @LightnessRacesinOrbit, thank you and my apologies for posting it - perhaps it would be best to write down a sticky that says "please do not post this topic". And Jared, cheers for the explanation; I totally understand now. – SirJames Jul 13 '17 at 13:59
  • @SirJames: It is described what is on-topic. It's the very first article in the Help Centre. https://stackoverflow.com/help/on-topic – Lightness Races in Orbit Jul 13 '17 at 14:01
  • @LightnessRacesinOrbit I understood it as a practical question. Perhaps I should've rephrased it in a way that was, "what is practical about not adhering to utilizing classes"? – SirJames Jul 13 '17 at 18:15
  • 1
    It's still a discussion / chat question. – Lightness Races in Orbit Jul 13 '17 at 18:16
  • @LightnessRacesinOrbit fair enough, technically I guess that's what this is right now. Cheers for the information! I learned a lot from this, regardless of the outcome. – SirJames Jul 14 '17 at 13:21

0 Answers0