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:
Input/Output:
    Number of Units
    Before/After state of the process
Process:
    How long did it take
    How much processing time is used
    How much memory did it use
    How much bandwidth was used
Output:
    How many were successful
    How many failed
    Why did they fail
    Which failed

Funnels

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

1
if ($ent === null) {
2
printf("Unable to load ent %d", $ent_id);
3
exit(1);
4
}
Copied!

Write code knowing you will be blamed

Tuples

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:
1
$metric = new Metric($metric_id);
2
$metric_partner = $metric->withPartner($partner);
Copied!

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.

Monitoring/Alerts

    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

Pros:
    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/
Cons:
    Regexes are slightly more time consuming
For example:
1
regex.matches(input)
Copied!
vs
1
inputs.split(',').some((input) => input === expected);
Copied!
Last modified 1yr ago