Let's take a look at one of the "most general" operations: add.
Please note that this also has ambiguity we wish to get rid of - because adding for a Python list involves creating a new, longer list, whereas the operation we're most interesting in is arithmetic addition.
We need to keep the Python list semantics while keeping the actual symbol add for addition.
Question 1:
Right now, you can say Color.by_name.red * 0.75 - so Color doesn't look like a tuple when it comes to * and + and arithmetic works neatly.
If we lost this, we'd be more consistent between Color and ColorListColor looks "very much like a tuple", except for this one detail.
Now we'd have to say: Color.by_name.red.mul(0.75) - not so bad really.
OK - done deal I think. That means that almost all of the magic methods goes away except for two adds and two muls (one each in the case of ColorConst).
So we then have these possible forms of this function:
add - returns a new instance.
add_to - add and store the result in an existing instance
Let's take a look at one of the "most general" operations:
add
.Please note that this also has ambiguity we wish to get rid of - because adding for a Python list involves creating a new, longer list, whereas the operation we're most interesting in is arithmetic addition.
We need to keep the Python list semantics while keeping the actual symbol
add
for addition.Question 1:
Right now, you can say
Color.by_name.red * 0.75
- soColor
doesn't look like a tuple when it comes to*
and+
and arithmetic works neatly.If we lost this, we'd be more consistent between
Color
andColorList
Color
looks "very much like a tuple", except for this one detail.Now we'd have to say:
Color.by_name.red.mul(0.75)
- not so bad really.OK - done deal I think. That means that almost all of the magic methods goes away except for two
add
s and twomul
s (one each in the case ofColorConst
).So we then have these possible forms of this function:
add
- returns a new instance.add_to
- add and store the result in an existing instanceadd_into
- add and store the result intoself
.I like this. Very clear!