Sunday, December 25, 2016

Orthogonality in Coding

Orthogonality is one of the most important properties that can help make even complex designs compact. In a purely orthogonal design, operations do not have side effects; each action (whether it's an API call, a macro invocation, or a language operation) changes just one thing without affecting others. There is one and only one way to change each property of whatever system you are controlling.
- The Art of UNIX Programming
Orthogonality means that features can be used in any combination, that the combinations all make sense, and that the meaning of a given feature is consistent, regardless of the other features with which it is combined.
- Programming Language Pragmatics
An orthogonal language is one in which you can express a lot by combining a small number of operators in a lot of different ways.
- On Lisp

The Principles of Modular and Maintainable Design by Jens Dietrich

Orthogonality is a concept often used to describe modular and maintainable software. The concept of orthogonality is based on the Greek word orthog┼Źnios, meaning "right-angled." It is often used to express the independence between different dimensions. When an object moves along the x-axis in a three-dimensional space, its y and z coordinates don't change. Change in one dimension does not cause change in another dimension, which means that one dimension cannot cause side-effects for others.

This explains why the concept of orthogonality is often used to describe modular and maintainable software design: thinking about systems as points in a multi-dimensional space (spawned by independent, orthogonal dimensions) helps software developers to ensure that our changes to one aspect of system will not have side-effects for another.

Orthogonality is a powerful concept because it enables us to establish a relatively simple mental model for complex application use cases. In particular, we can focus on one dimension while ignoring other aspects.

Testing is a common scenario where orthogonality is useful. We can test the functionality of log levels using a suitable fixed pair of an appender and a layout. Orthogonality ensures us that there will be no surprises: log levels will work the same way with any given combination of appender and layout. Not only is this convenient (there is less work to do) but it is also necessary, because it would be impossible to test log levels with every known combination of appender and layout. This is especially true given that Log4j, like many software tools and utilities, is designed to be extended by third parties.

Designing and coding for orthogonality

 The key idea is to use abstraction. Each dimension of an orthogonal system addresses one particular aspect of the program. Such a dimension will usually be represented by a class. Each of these classes represent a dimension, while the objects represents the points within the given dimension.

Pending Work: This code here:  Monads in Recurring Payment Handling seriously needs some orthogonal love.


 Flattening Arrow Code
 Arrow Anti Pattern
 Java Tip: Orthogonality by example by Jens Dietrich

No comments:

Post a Comment