More random python observations from a perl programmer

Roy Smith roy at popmail.med.nyu.edu
Sun Aug 22 17:00:06 CEST 1999


Les Schaffer <godzilla at netmeg.net> wrote:
> what does orthogonality mean here?

Two concepts/variables/things/whatever are orthogonal if either can assume
any legal value with no effect on the other.

For example, color and style, which describe a house.  Color can be any of
red, blue, green, brown, or white, and style can be any of colonial,
ranch, victorian, or cape_cod.  Any of those styles of house can be
painted any color, so color and style are orthogonal.

But, let's say we had two other variables describing the house,
roof_material, and roof_color.  You can have the same assortment of colors
for the roof as above, and the materials can be shingle, ceramic_tile, or
metal.  Assume that ceramic tiles only come in red, green, or brown. 
Roof_material and roof_color are NOT orthogonal; while color can be white
or green, it can only be so if material is not ceramic_tile.

So it is with types and operators.  Let's say a language has three types,
int, float, and string, and has a bunch of operators, add, subtract,
multiply, etc.  The language is orthogonal if any operator can apply to
any type(s).  Some operators in python could apply to ints, floats, and
strings, so any of:

x = 4 + 3
x = 4.0 + 3.0
x = "Four" + "Three"

are legal, with x getting the value 4, 4.0, and "FourThree" respectively. 
But, not all operators can be applied to all types.  Thus:

x = 3 * 4

is legal, as is:

x = "Three" * 4

but:

x = "Three" * "Four"

is not.




More information about the Python-list mailing list