Python is the language I use most in this period.
My background in Java
Before start learning Python I have programmed in Java language. In Java all code is written inside the methods of a class and variables are attributes of a class. In general is a best practice to avoid using static methods, public variables and so on.
Python is different from Java: encapsulation is difficult
When I started programming in Python I tried to do the same thing by writing code inside methods of a class and variables as attributes of a class. However, I realized that Python is different from Java in many aspects. For example, the concept of
private variable or method is missing although particular names (
__variable_name) can be used to hide attributes outside of the class. This makes encapsulation difficult.
After the initial period of Python programming, I have reduced the use of classes and I have started to write code and variable inside a simple Python module without create class.
Below I report an interesting comment that @JimmyJames has written in one other post:
My opinion is that with Python, you should use module level code as long as it meets your needs and isn't becoming spaghetti code and only introduce classes when they provide a clear benefit.
This is already a confirmation that in Python modules are preferable than classes, but I'm here to look for a most specific indication.
In python when is absolutely preferable use a class than a module?