golang

Optimising programming

The order in which optimisation has to be done:

  1. Optimise latency of network, disk IO, etc
  2. Memory allocation
    1. Garbage collection
  3. How we access data, how efficiently we access data
  4. Algorithmic efficiency
    1. This should be the last, since the hardware is fast enough to ignore this whereas the above 3 are the major optimisations to focus on.
  • Optimise for correctness over performance. You read code more than writing code.

Integrity - We need to become very serious about reliability

  • integrity is the highest priority

  • Micro level - memory read and writes are always accurate and correct.

  • Macro level - Every program end of the day does data transformation. Data oriented design is important. Go is data orient design over object oriented design.

  • Write less code. Less code less developers easier to maintain.

  • Every 1000 lines introduces an average of 15-50 bugs.

  • More lines of code More tests

  • Code eventually turns legacy when engineering turns into hacking, where tests, principles goes out of the window.

  • Majority of code is written for handling errors, the ugly path. The happy path code is very little.

Readability - 2nd most important aspect after integrity

  • Average developer should be able to understand the mental model of the project.
  • Should be able to solve every bug WITHOUT a debugger. Using a debugger implies bad logging, bad readability, bad mental model.
  • Not hiding the cost of the code written.
    • Too much abstraction can hide costs which can be critical for optimisation.
    • Writing code which runs on the real machine compared to writing code which doesn’t run on the real machine such as JVM, etc which require a dedicated environment. This can hide costs.