Re:Swift Operators
by angersock on Monday August 11, 2014 @02:15PM
(#8164440)
One bit of advice left out is very handy: define operators in terms of their inverse.
For example, if I have a != and an == for comparing vectors (terrible, terrible, I know, but it serves as a useful case study), I should only implement one (probably ==), and define the other as simply !(==). This helps make sure that bugfixes to one operator automatically apply to its complement.
For example, if I have a != and an == for comparing vectors (terrible, terrible, I know, but it serves as a useful case study), I should only implement one (probably ==), and define the other as simply !(==). This helps make sure that bugfixes to one operator automatically apply to its complement.