3Cs of Coding

https://blog.intzone.com/3cs-for-coding-consistency-context-continuity/
Talk Agenda
  • Consistency
  • Context
  • Continuity
3Cs of Coding - Consistency
Reduces cognitive friction

   // sample MESSY Code
function test(id){
    if ( id == 1)
        console.log('One');
  if (2 === id ) {
    console.log("TWO");
  }
}
            
Reduces time-consuming guesswork

// personId, person_id, PERSON_ID, personID, /person[-_]?id/i
{
  "snake_case": 1,
  "camelCase": 2,
  "PascalCase": 3,
  "kebab-case-sounds-tasty": 4,
  "CAPS": 5,
  "sUpErCaLiFrAgIlIsTiCeXpIaLiDoCiOuS": 6
}
            
Reduces unwanted surprises

docker-compose -f ./my-app/docker-compose/prod/db.yml up -d
docker-compose -f ./my-app/docker-compose/prod/redis.yml up -d
docker-compose -f ./my-app/docker-compose/prod/flyway.yml up
docker-compose -f ./my-app/docker-compose/prod/flyway.yml down
docker-compose -f ./my-app/docker-compose/prod/api.yml up -d
docker exec -it my-api npm run seed:run
docker-compose -f ./my-app/docker-compose/prod/app.yml up --build -d
            
3Cs of Coding - Context
Preserved via docblocks

function z(q, r) {
  // Imagine reading 1000 lines to try to understand what the method does,
  // what it takes in for input and what output it returns
}

/**
 * Compute height based on aspect ratio
 *
 * @param {float} width - Width in pixels.
 * @param {float} aspectRatio - If 16:9, this value will be 0.5625 (9 / 16).
 * @returns {float} Corresponding height.
 */
function computeHeight(width, aspectRatio) {
    // Imagine it's still 1000 lines but you can skip reading cos of the
    // docblock above :)
}
            
Preserved via comments

document.querySelector('video').addEventListener(
    'webkitfullscreenchange',
    function (event) {
        // GitHub issue #123: webkitendfullscreen doesn't work in macOS Safari
        // Must add listener on video element itself, not the document
        console.log(event);
    }
);
            
Preserved via documentation

# Sample README for a project

  This is stored as `README.md` in the root of the source code repository.
  Paths mentioned here are relative to the root of the repository.

  ## Installation
  - Clone this repo.
  - Run `npm install`.

  ## Deployment
  - The code is deployed using GitHub Actions. See `.github/workflows` folder.

  ## Workflow
  - This section explains the customer journey and the architecture.
            
3Cs of Coding - Continuity
Involves bus factor
Involves HR
Involves professionalism