modeling well being by using programming allegories in the guise of javascript programs

Why programming and philosophy?

By working on a company whose main objective is enhancing well-being on the one part and on the other having been exposed to some philosophy during part of my studies, I progressively asked myself: what it is exactly we are trying to enhance in people? How can we define and measure it (if even possible)? What are the most saillant definitions that have been proposed by philosophers? Moreover, being a programmer in this company I started to think about programming as a kind of tool that could help me to develop a vastly simplified but, I hope, coherent, image of well-being. While haunting some bookshop with these ideas progressively crystalyzing in my mind, I stumbled upon a very thought-provoking and entertaining book, If Hemingway wrote javascript, by Angus Croll. The main purpose of the book is to illustrate the style and spirit of a varied cast of prominent literary authors via a short list of computer science problems and implement it as a short javascript program. This book solidified my desire to use programming artifact as a kind of heuristic device for understanding a philosophical notion, human well-being.

Here I will use Javascript for third main reasons, first this is the main language we use at work on a daily basis. The second is that it can provide a more familiar view of philosophical concepts for readers maybe more familiar with the syntax of programming than with philosophical vocabulary. The third is that I see it at a stimulating and fun exercise to make two distinct disciplines dialog with each other.

Hopefully, the use of javascript as our metaphor / model will allow us to gain some insight on what well-being is and maybe some ideas or intuitions on javascript practice.

How, the method

I will try here to formalize some of our more coherent intuitions about well-being by examining several important philosophical theories. For each theory, we will construct a simplified but functional concept by using the following constraints:

Once we have such a concept we will use a short piece of javascript as a heuristic device to help us express the meaning of the concept in a more formal and non ambiguous way. Finally we will very briefly mention the javascript tools that were useful in the process and why we used them.

In this article we will focus on one theory of well-being centered around pleasure and pain avoidance.

Well-being as hedonism

The first theory we are approaching pertains to the utilitarianism school of philosophy, that counts among its most eminent members John Stuart Mill (1806- 1873) and Jeremy Bentham (1748 - 1832). Utilitarianism starts to emerge as a coherent and public theory with the works of Jeremy Bentham. According to him pleasure and pain are the great masters of the human race : “‘Nature has placed mankind under the governance of two sovereign masters, pain and pleasure.”

(source).

In this context well-being is defined as the greatest balance of pleasure over pain. Thus, to increase our well-being we must seek experiences that we find pleasurable and avoid pain-inducing activities (except if they bring a higher level of pleasure (e.g. a musician works for hours on a partition, feeling small amounts of pain in exercising his skill but the resulting pleasure of playing good music will be more important for his well-being). We will use here the conception of Mill that the quality of the pleasure is important: not all pleasures are equal in their contribution to our well-being.

hedonism.js

import { isObject } from 'lodash';

export class Experience {

  /**
   * Experience is defined by pain and pleasure. We take into account the quality
   * of the pleasure experiences, following J.S. Mill here as opposed to Bentham.
   * @param  {Number} pain             [description]
   * @param  {Number} pleasureQuantity [description]
   * @param  {Number} pleasureQuality  [description]
   * @return {Object}
   */
  constructor(pain, pleasureQuantity, pleasureQuality) {
    this.pain.quantity = this.limitExperienceValue(pain);
    this.pleasure.quantity = this.limitExperienceValue(pleasureQuantity);
    this.pleasure.quality = this.limitExperienceValue(pleasureQuality);
    this.qualityModfier = 2;
    this.experienceLimitValue = 10;
    /* Without taking into account past experience we define the default level of
    * experience to be neutral.
    */
    this.wellBeingValue = 0;
  }

  /**
   * We limit the field of experience to
   * @param  {Number} experienceValue [description]
   * @return {Number}            [description]
   */
  limitExperienceValue(experienceValue) {
    const tempExpValue = Math.abs(experienceValue);
    return tempExpValue > this.experienceLimitValue
    ? this.experienceLimitValue
    : tempExpValue;
  }

  /** An experience that doesn't increase pain nor pleasure doesn't affect the
   * user well-being
   * @param  {Experience} experience
   */
  getWellBeingValue(experience) {
    if (!isObject(experience) && !(experience instanceof wellBeingComponent)) {
      throw new Error('This experience doesn\'t enter our model');
    }
    // Well-being is positive
    const isPositivePleasurePainRatio = experience.pleasure.quantity > experience.pain.quantity;

    // Well-being is positive
    if (isPositivePleasurePainRatio) {
      /**
       * Following J.S. Mill type of hedonism, quality has an impact on
       *  well-being
       */
      this.wellBeingValue = 1 * experience.pleasure.quality;
    } else {
      /* Well-being is negative or neutral (equal to 0) if the pain quantity of the
      * experience is equal to or superior to the pleasure quantity
      * The quality modifier is not applied when the pleasure quantity is lower
      * than the pain quantity, modeling the fact that avoiding pain is a priority
      * over gaining higher quality pleasures.
      */
      this.wellBeingValue = experience.pleasure.quantity - experience.pain.quantity;
    }
  }
}

/**
 * Some tests to assert the logic of the model.
 * tests/experience.test.js
 */

import { assert } from 'chai';
import Experience from 'Experience';

  describe('Experience', () => {
    it('returned well-being value should be positive and equal to 1', () => {
      const exp = new WellBeingComponent(0,1,1);
      const wellBeingValue = exp.getWellBeingValue();
      assert.equal(wellBeingValue, 1);
    });
    it('returned well-being value should be negative (more pain than pleasure) and equal to -4', () => {
      const exp = new Experience(5, 1, 1);
      const wellBeingValue = exp.getWellBeingValue();
      assert.equal(wellBeingValue, -4);
    });
  });