Multi-paradigm programming

This article is part of a series of six articles:

The more you read about different programming models such as functional or object oriented programming the more you get a feeling of how biased supporters of different models behave. This series of posts is an effort to provide a bigger picture of programming as a whole in order to get rid of our own shortsightedness.

What do we understand under “programming”?

  1. The computation model, a formal system that defines the language and how the language is executed.
  2. The programming model, a set of design techniques and principles used to write programs in the language of the computation model.
  3. A set of reasoning techniques to let you reason about programs to increase confidence that they behave correctly and efficiently.

Using only one computation model does not yield the benefits you might expect and it’s often very helpful to combine multiple computation models in one program. It’s an obvious trend that programming languages get new features that stem from other programming paradigms, i.e. anonymous functions. Combining multiple models and techniques is also known as multi-paradigm programming.

The limits of single models

  • Object-oriented languages encourage the overuse of state and inheritance. In many cases a simpler programming model would suffice and especially inheritance is often misused.
  • Functional languages encourage the overuse of higher-order programming. Monads are typical examples. Monads thread state throughout the program but do not achieve the modularity of true explicit state.

There is one rule that will change your programming style forever: The rule of least expressiveness.

When programming a component, the right computation model for the component is the least expressive model that results in a natural program.

When you decide to implement anything you should always ask yourself — what is the simplest model possible to implement this component?

Resources: CTM