BreakingBytes / simkit

Model Simulation Framework
http://breakingbytes.github.io/simkit/
BSD 3-Clause "New" or "Revised" License
27 stars 16 forks source link

add explanation and justification for metaclasses and conventions to docs #82

Open mikofski opened 7 years ago

mikofski commented 7 years ago

metaclasses are used extensively in Carousel, so I think it's a good idea to document how they are used and to set some ground rules for their usage.

metaclasses

Here are some reasons to use metaclasses in Carousel:

conventions

Since metaclasses are altering the way that classes are created before they are even instantiated, this leads to magic that can be confusing at runtime because it is implicit. The Zen of Python says that explicit is better so rather than inferring objects at runtime, there should be only published objects. All inferred objects should be in dictionaries that are mutable at runtime. For example, in the same way that monkey patching is considered by some a code smell, even though it is sometimes necessary, but editing a dictionary at runtime is fair game.

  1. class attributes should be published. there should be no inferred objects in class instances.
  2. any objects that are created dynamically at runtime should be collected in a dictionary or list or other mutable container.
mikofski commented 7 years ago

Actually, you could build a model up component by component using the add and edit features in layers.Layer just like Keras and other models (eg: the modelchain in PVLIB), but it still requires subclasses and sources, like Data to be defined. But this could be an interesting alternative for some people?