L
L
loki172017-12-04 20:07:59
Python
loki17, 2017-12-04 20:07:59

Is it worth it to bring everything to classes?

I'm new to Python, I used to write in C++. Prompt, how much correctly all to lead to user objects. Those. for example, I have a file with script settings, I can simply load it as a dictionary and then use the settings from the dictionary, or I can first load all these settings into a class object and use this object everywhere. Why the question arose - because it seems to me more convenient to use settings in the form of an object in different parts of the library, for example, settings.max_pool_size, instead of using the settings['max_pool_size'] dictionary. In the first case, many IDE goodies work, such as hints.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
S
sim3x, 2017-12-04
@sim3x

Keep It Simple S

A
artem78, 2017-12-04
@artem78

Using objects everywhere unnecessarily is absurd. Do what is most convenient for you.

A
Alexey Cheremisin, 2017-12-04
@leahch

I use functions more often, since python is also functional. I use classes as needed when they themselves are asked, for example, to collect a state, or for identical entities, or for inheritance.
And yes, I also program in Java, where each sneeze is an object.

F
fdrwitch, 2017-12-05
@fdrwitch

In a simple way, as they write in books (see Summerfield), classes when several hundred lines of code are long ...
In a complex way, you can compose a class for 50 lines. This is when you need to compose a complex multi -type
(in the sense of C) structure with its own specific functionality (Romaglio's deck of cards comes to mind at the
very beginning of his book, and then, this is purely for explaining sequence and iteration and using the necessary special methods).
But the library standard is so big and complete, and, if
not a specially cunning show off, then there are quite a few modules or even biltinz ...
even more so for the files.
Note that dictionaries are the strongest feature in python and sharpened besides (especially after 3.6)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question