python-tutorial icon indicating copy to clipboard operation
python-tutorial copied to clipboard

Add Some OOP-related Contents to the List

Open lemorage opened this issue 1 year ago • 2 comments

That's really a good tutorial to start with. After learning some of the basics of Python, however, classes seem to be a quite sophisticated topic. Do you think it would be better to add more conceptual stuff built on classes, like inheritance or polymorphism, etc?

lemorage avatar Apr 01 '24 12:04 lemorage

We could add more OOP stuff, but before doing that, we should explain when classes are used. Currently the tutorial does a good job explaining how classes work, but not so much when to use them. IMO you should use:

  • a plain old class when you end up with many functions that all access the same data
  • a dataclass when you just want to group together related data (similar to struct in other languages)
  • fancy OOP things (inheritance etc) only in some rare cases.

Many people overuse fancy OOP things, and are too arfaid to break OOP's "rules" when it makes sense. Most of the time it's best to use a plain old simple class. That said, sometimes inheritance is the right tool for the job, and programmers should know it.

Akuli avatar Apr 01 '24 16:04 Akuli

Yep, yep, really class is a quite complicated topic for me compared to those basic things in Python, and sometimes I just can't find a practical way to apply the OOP concepts to my case, and I can only handle a simple old class which seems pretty lame. We really need to make a good structure of these concepts and explain the possible use cases.

lemorage avatar Apr 02 '24 07:04 lemorage