next up previous contents
Next: Instance-specific Dispatch Up: Naming Methods Previous: Performing Actions   Contents

Binary Operators

These are perhaps the most controversial of any programming language's protocols. In the Smalltalk family of syntax, there are no precedence orderings between operators of different names, so the issues with those do not arise. However, it is very tempting for the library author to re-use mathematical symbols for her own domain, to allow her users to have a convenient abbreviation for common operations. While this benefits the writer of code which uses her library, there are domains and situations that punish the reader of the code that results.

For example, mathematical addition and multiplication symbols, ``+'' and ``*'', are generally associative and commutative. That is, repeated calls to these should be able to re-order their arguments arbitrarily and achieve the same result. For example, $3+4+5=4+3+5=5+4+3$. However, string concatenation (as an example) is not commutative; we cannot re-order the arguments and expect the same result, i.e. "gold"+"fish"="goldfish" , whereas "fish"+"gold"="fishgold" . Because concatenation is associative, however, we can re-use the punctuation style of the semi-colon ``;'' and achieve intuitive results. This general style of reasoning should be applied wherever this type of operator name re-use could arise.


next up previous contents
Next: Instance-specific Dispatch Up: Naming Methods Previous: Performing Actions   Contents
Brian Rice 2004-08-24