2019-05-20 | Paul Boddie | file changeset files shortlog | Experiment with a temporary attribute on objects. This attribute must be cleared when assignments occur, but it should also be cleared when objects escape from functions (which is not yet done). Since the motivation for marking objects as temporary is their re-use in certain operations, the objective is to avoid objects being used in multiple places and still being marked as temporary and potentially undergoing re-use/mutation. Perhaps the only way of guaranteeing exclusive access to an object is if it is provided as a function result and is immediately passed to a function or operation, with this function either mutating the object or ensuring its direct propagation to another such function. | temporary-object-experiment |
paul@816 | 1 | class MixIn: |
paul@816 | 2 | def f(self): |
paul@816 | 3 | return self.g() |
paul@816 | 4 | def f2(self): |
paul@816 | 5 | return self.g2() |
paul@816 | 6 | |
paul@816 | 7 | class Concrete(MixIn): |
paul@816 | 8 | def g(self): |
paul@816 | 9 | return 13579 |
paul@816 | 10 | def g2(self): |
paul@816 | 11 | return 13579 |
paul@816 | 12 | |
paul@816 | 13 | class Cement(MixIn): |
paul@816 | 14 | def g2(self): |
paul@816 | 15 | return 24680 |
paul@816 | 16 | |
paul@816 | 17 | m = MixIn() |
paul@816 | 18 | |
paul@816 | 19 | try: |
paul@816 | 20 | print m.f() |
paul@816 | 21 | except TypeError: |
paul@816 | 22 | print "m.f: cannot obtain attribute" |
paul@816 | 23 | |
paul@816 | 24 | c = Concrete() |
paul@816 | 25 | print c.f() # 13579 |
paul@816 | 26 | |
paul@816 | 27 | try: |
paul@816 | 28 | print m.f2() |
paul@816 | 29 | except TypeError: |
paul@816 | 30 | print "m.f2: cannot obtain attribute" |
paul@816 | 31 | |
paul@816 | 32 | c2 = Cement() |
paul@816 | 33 | print c2.f2() # 24680 |