What is the point of defining new class as a struct in Python C API
Question: [The docs for Python C
API](https://docs.python.org/2/extending/newtypes.html#the-basics) describes
the pattern of defining a new type:

    
    
    typedef struct {
        PyObject_HEAD
        PyObject *first; /* first name */
        PyObject *last;  /* last name */
        int number;
    } Noddy;
    ...
    

Then methods such as `init` could be added.

My question is - what is the point to define custom fields in a struct, why
not define them in `init`, just like in Python, using
[PyObject_SetAttr](https://docs.python.org/2/c-api/object.html#c.PyObject_SetAttr)
function calls on `self`?


Answer:   1. Struct member access is far more efficient than dict lookups.
  2. Struct member access is far more _convenient_ to do in C. It's much easier to do `thing->foo` than `PyObject_GetAttrString(thing, "foo")`.
  3. Using struct members allows you to store data that isn't of a Python type. This allows you to do things that can't be implemented in terms of Python types, or that would be much less efficient in terms of Python types.
  4. Using struct members prevents every object from needing its own dict. The most important result of this is that a dict doesn't have to have an infinite descending chain of dicts, but it also improves space efficiency.
  5. This API existed before Python-level `class` statements and the way those statements do things.

