Friday, January 1, 2010

Symmetry in Software

Symmetry is a powerful concept in mathematics and physics. It is used to analyze and construct elegant theories. Take for example the Supersymmetry theories in particle physics. They provide an elegant way to describe the zoo of particles.

The abstract definition of symmetry deals with the notion of invariance. When an entity has a property which is invariant under certain transformation we say that this entity is symmetric under the transformation. The most famous symmetries in mathematics are present in geometry. In geometry we find geometrical figures which exhibit various kinds of symmetries. Those geometrical figures are often said to be esthetic or elegant because of their symmetries. Symmetry in general is part of being beautiful.
The first time I heard about symmetry in connection with software was several years ago when I went to hear a lecture by Jim Coplien. His lecture talked about symmetry and symmtery breaking in SW.

Since symmtery is such an abstract concept in mathematics, it can be applied in many ways to SW. One of the most effective ways of using symmtery is doing a refactoring. When you are doing a refactoring you want to change the structure of the SW while leaving the functionality invariant. That is, the SW should be functionaly symmteric under the restructuring transformation.

Another application of symmtery can be found in the Object Oriented concept of polimorphism. When we use polimorphic elements, either compile time polimorphism or run-time polimorphism, we are counting on the fact that the actual code should be invariant when we change the element to one of its polimorphic instances. That is, the code is symmteric under the transformation of replacing the polimorphic elements.

Yet another, quite trivial, example is comments in the code. We can say that the funcionality of a code is symmteric under the transformation of changing the comments.

I said that symmtery can often be connected to elegancy and beauty. We can find elegance and beauty in a good SW design and symmtery is often used in elegant design. We can even appreciate the symmtery using our sense of visual beauty when we describe the design using diagrams. The same design can be percieved more elegant if it is presented in a symmteric diagram than if it is presented in a chaotic diagram.

If you have more examples for symmtery in SW you are welcome to write about them in the comments. I will further post symmtery examples whenever I come across interesting examples.

Khen Ofek

No comments:

Post a Comment

 
Creative Commons License
Cloud Computing Blog by Khen Ofek is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 2.5 Israel License.