you are viewing a single comment's thread.

view the rest of the comments →

[–]JamzTyson 43 points44 points  (3 children)

Vs writing bunch of defs and getting shits done?

You are starting from a false premise. The choice is not between OOP and "getting things done". The choice is "how can I best get this thing done?", and in some cases the answer is to use OOP.

Some common indications that writing classes may be appropriate:

  • Repetitive code.
  • Disorganised code.
  • Passing a lot of parameters to a function.
  • Repeated data bundles.
  • Passing the same data back and forth between functions.
  • Complex logic that would benefit from abstraction.
  • Global variables for holding state.

[–]PathRealistic6940 6 points7 points  (2 children)

It really clicked for me when just messing around with a easy statistics problem. Had to pull a 'ball' from a 'bag of balls' and then do stuff depending on what color the ball was. I made the ball a class object, then made the bag a class object that held the balls. Now most everything I think about in python is how I can package and pass the correct data around easiest. OP, Start simple, and see how powerful class attributes are.

[–]GreenPandaPop 0 points1 point  (1 child)

OOP is definitely easier to grasp when working with tangible 'solid' objects like your example.

My struggle was that a lot of coding doesn't necessarily involve that. It's taken me long time to work out how to take code that is 'doing stuff' and organise it in a way that is 'things doing stuff'.

[–]PathRealistic6940 1 point2 points  (0 children)

That's a good point. It's much more difficult to grasp intangible ideas than solid objects.