Avoiding metaprogramming where not required
Writing too much metaprogramming just because the feature is available in Python also makes the overall code very complex and hard to handle. The following aspects should be kept in mind while choosing to write a metaprogram for your application:
- Identify your use case and determine the need for metaprogramming based on how frequently you need to modify the code.
- Understand how frequently you need to manipulate your code outside of its core elements such as classes, methods, and variables.
- Check whether your solution can be developed with object-oriented programming alone or whether it depends on elements such as metaclasses, decorators, and code generation.
- Check whether your team has the relevant skills to maintain the metaprogramming features after development.
- Check that you don’t have a dependency on earlier versions of Python that do not support some of the metaprogramming features.
These are some...