CSV framework Flashcards
Declarative framework
You declare what you want, rather than walking the computer through what to do. The latter is referred to as imperative programming.
Python is famous for being very declarative - good and bad. It looks like magic, but it makes things very easy to get done.
Declarative frameworks are helpful if you have:
- many potential configurations
- each configuration is known in advance
- many instances of any given configuration
- actions that can be performed on a given instance
Three primary components of a declarative framework
- Base class - gives frame w place to hook in and process declarations. Attaching a metaclass provides machinery to inspect the declaration at runtime to make adjustments.
- Various field types - attributes inside class declarations. represent data attributes in structures defined by your framework. Must know the order in which they’re instantiated, so ordering used in the declaration is the same used later on.
- Options container - some type of class-wide option, not specified on every field. –need example
Managing options
primary purpose of an options container is to store and manage options for a given class declaration.
Options are simply a map of names to values.
call it options.py. The bulk of work is done in the __init__() method.
Options should have defaults so users don’t have to keep declaring the most common thing. If something is truly required and doesn’t have a reasonable default, it should be supplied as an argument, rather than being an option.
Defining fields
containers for data:
databases call them columns
forms call them inputs
functions call them arguments.
- define a base field class to describe what it means to be a field
- defines API, how subclasses should behave, how they fit in with the system
Fields are part of the declaration and assigned as attributes on the class. Since they’re instantiated as part of the declaration, all the work has to be done in __init__().