When I need classes?

Bernardo Sulzbach mafagafogigante at gmail.com
Mon Jan 11 19:53:44 EST 2016


On Mon, Jan 11, 2016 at 9:45 PM, Travis Griggs <travisgriggs at gmail.com> wrote:
>
>> On Jan 10, 2016, at 9:48 AM, Bernardo Sulzbach <mafagafogigante at gmail.com> wrote:
>>
>> Essentially, classes (as modules) are used mainly for organizational purposes.
>>
>> Although you can solve any problem you would solve using classes
>> without classes, solutions to some big problems may be cheaper and
>> more feasible using classes.
>
> I think, this is often why, for a simple script, OO just kind of gets in the way. You have a straightforward procedure that you just want to do. The state (data) is not rich enough to make making it the focal point of your program.

Your answer is quite good. I am not a purist myself (when it comes to
Java and C++, I am never going to instantiate a Math class to get a
logarithm function), but I understand the value of OO from experience.
As I mentioned those "tuples and dictionaries" to pass data around, I
would like to add that when a single script has two kinds of tuples or
dictionaries, you may be better of using two different classes, as
having "dedicated" types simplifies project organization and
enhances readability.

I have never gone "seriously OO" with Python though. I never wrote
from scratch an application with more than 10 classes as far as I can
remember. However, I would suppose that the interpreter can handle
thousands of user-defined classes simultaneously.

-- 
Bernardo Sulzbach



More information about the Python-list mailing list