Context-Oriented Programming

Examples are great but they have a context problem.

The idea of (test-)state construction is good because they follow the model use cases. But they are global and inflexible to different environments which have to be defined at the root of an example. That is something TestCases are good for. But TestCase don‘t help much in state construction. Some things can be mitigated using context oriented programming with dynamic variables. But at the end the meeting point of all of these is a global location which makes them not easy to use. (Norbert Hartl, post )

In the context of the Federated Wiki, a global location is a Page. post

~

With Moldable Development we use examples rather than tests. Basically these are unit tests that return a live instance that you can interact with.

HIRSCHFELD, Robert, COSTANZA, Pascal and NIERSTRASZ, Oscar, 2008. Context-Oriented Programming. Journal of Object Technology. 2008. Vol. 7, no. 3, p. 125–151. pdf

Context-dependent behavior is becoming increasingly important for a wide range of application domains, from pervasive computing to common business applications. Unfortunately, mainstream programming languages do not provide mechanisms that enable software entities to adapt their behavior dynamically to the current execution context. This leads developers to adopt convoluted designs to achieve the necessary runtime flexibility. We propose a new programming technique called Context-oriented Programming (COP) which addresses this problem. COP treats context explicitly, and provides mechanisms to dynamically adapt behavior in reaction to changes in context, even after system deployment at runtime. In this paper we lay the foundations of COP, show how dynamic layer activation enables multi-dimensional dispatch, illustrate the application of COP by examples in several language extensions, and demonstrate that COP is largely independent of other commitments to programming style.