Other rules

Rules I haven't formatted properly

2 biggest problems in programming

  • Naming

  • Caching

  • Off By One Errors

Naming Good Names (files, directories, classes, methods)

Avoid Single Letter Variable Names

Leave It Better Than You Left It

Small Functions

Input > Process > Output

Output can be an Input for another step

Measure Input > Process > Output

What to Measure:


  • Number of Units

  • Before/After state of the process


  • How long did it take

  • How much processing time is used

  • How much memory did it use

  • How much bandwidth was used


  • How many were successful

  • How many failed

  • Why did they fail

  • Which failed


When there are many Input > Process > Output, then you have a funnel.

Break down a Proces

Handling Errors

Silent Errors vs Fataling

Always print IDs

if ($ent === null) {
  printf("Unable to load ent %d", $ent_id);

Write code knowing you will be blamed


Sometimes we need to pair two variables together to represent a single datatype. For example tuple(MetricID, Partner) which tells us that this represents the MetricID for a given Partner.

You may want to consider 2 data structures for this:

  • Metric(MetricID)

  • MetricPartner(Metric/MetricID, Partner)

It is easier moving from a data structure that manages one data type, to a data structure that manages 2.

Consider having a function in Metric which takes in a Partner and returns a MetricPartner. For example:

  $metric = new Metric($metric_id);
  $metric_partner = $metric->withPartner($partner);

Deep inheritance trees are bad

Be careful of parameter bags

Single Responsibility Principle (SRP)

Use intention revealing names

2 hardest parts of programming

Write code that is meant to be read, and not meant to solve a problem

Duplicating calls is ok.


  • How many lines of code are being added?

  • Are there alerts on highly sensitive parts of the codebase?

For user input: consider using Regexes instead of String comparisons


  • More flexibility in matching strings

  • Regexes don't require precise string matching

  • Can easily match more than one string, for example to match all branches where node8 work is done: /\.*node8/


  • Regexes are slightly more time consuming

For example:



inputs.split(',').some((input) => input === expected);

Last updated