Objects, attributes, maps, oh my! 0 ▲ Max Bernstein's Blog 1 hour ago · 14 min read2895 words · Tech · hide · 0 comments Or, IC UC we all C for ICs. In many dynamically typed programming languages, objects look like a big ol’ mapping of names to values. The languages encourage this flexibility. Consider for example Python: class C: def __init__(self): self.a = 1 self.b = 2 Or Ruby: class C def initialize @a = 1 @b = 2 end end Or JavaScript1: let obj = {}; obj.a = 1; obj.b = 2; This might encourage the VM implementor to model object attributes using a hash table. Hash tables, after all, are very good at mapping names to values. Here is, by way of example, a Python sketch of what this object model looks like. Because it is a sketch, it uses write_attr and read_attr instead of the much more common syntax that your programming language comes with. MISSING = object() class Instance: def __init__(self): # TODO: the rest of your object system self.cls = ... self._fields = {} def read_attr(self, fieldname): return self._fields.get(fieldname, MISSING) def write_attr(self, fieldname, value):… No comments yet. Log in to reply on the Fediverse. Comments will appear here.