I’m learning Python and it seems to be too dynamic to me. Application of some of the dynamic/functional features I understand. For example, you can use dynamic typing to write functions that behave the same for complex and real numbers. But application of others seems obscure to me.
So here is my question. Please give examples where the following Python features are actually useful:
- Lack of private variables.
- Ability do define methods and variables in runtime.
- Ability to replace methods in runtime.
(Maybe some other features will appear here – I’m still learning.)
Lack of private variables: you don’t have to waste time declaring every variable public or private. Most of the stuff is usually public. If you think that a directly variable accessed without getter/setters will break things, you can use the convention of naming it with underscore: e.g. self._metadata.
Ability to define methods and variables in runtime: This is non-python-specific, general question regarding dynamic languages. One important use case is alternative to function pointers and polymorphism. Rather than compiling on-hand all kinds of functions you’d encounter, you can dynamically make/change things on the fly.
Ability to replace methods in runtime: this is again mainly used for polymorphism and function pointers. You have a running HR system with a policy in place. You want to make some changes in the policy. Rather than recompiling the whole system and restarting the system, you can just inject the new policy and replace the policy related method(s).
You might want be interested in this article: http://www.paulgraham.com/diff.html