Thumb quick good rules to decide to create a new function or create a new class in Python?

I'm not sure stackoverflow is the place to ask for general advice, so let me know if not, but here it is:

  • What are good rules of thumb when deciding whether to create a new class for a function or just add a function to the current class?

  • What are good rules of thumb when deciding to create a new function that takes data from a previous function or simply continues an old function?

I'm starting to read object oriented programming, but are there any quick good rules you could share?

Background: I am learning python to retrieve data through an API, manipulate it and send a report via email. Since this is just a long script (although there are now about 2000 lines), I could theoretically make one long function.

Despite the fact that I divide it into modular pieces for readability and ease of construction, I arbitrarily decide how long the function should be or how many functions should be contained within the class. I often ask myself if I should just extend my function or make my functions as short as possible or create a new class for a new function. I see functions and classes as a form of categorization, so I think I miss the fundamental concept of object-oriented programming in general.

, . , , . , , .

+4

Source: https://habr.com/ru/post/1523798/


All Articles