dict – at the heart of python, perl and javascript OO

Q: why is dict so central to python OO?
%%A: method object — python methods are easily modeled as code objects (just like fields), therefore more dict-friendly. Recall the regular dict stores key and value objects.
%%A: ultra-virtual — both field and method lookup is a runtime dict search. Note java/c++ does runtime search only for methods, not fields.
%%A: namespace — is a kind of dict. Namespaces are central to inheritance (and presumably overriding)

dir(), vars(),__dict__  … often returns something like a dictionary.

Note the dict in this context is a kind of “kernel-dict”. On the other hand, the user-defined dict is probably a “userland dict”. They share the same syntax. Implementation wise, they may differ. kernel-dict is probably memory efficient and in implemented in C. These various types of dict probably implement a consistent “interface”.

When people say an “import sys” creates an object named “sys”, it probably means a dict created in memory.

———–
In Perl OO, a hash is at the heart of every class. This is the “userland dict”.

———–
In javascript, “associative array” is closely related to (if not the basis of) user-defined objects

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s