Coding Standards

Spaghetti belongs on plates, not in our codebase. WIP.

Preface

There's no one perfect solution. Every decision is always a trade-off.

Solutions tend to create new problems, and the best solution is the one that solves the most pressing problems while creating the least amount of new ones.

In case we haven't already mentioned it, make sure to rebase onto main before continuing work.

We're huge on clean code. Code will be read more than it is written. Thankfully you don't have to memorize all of the conventions, as most of them have been automated by ESLint.

If you have the ESLint extension in your IDE, you will immediately see some annoying red and yellow squigglies underneath your code. Thankfully, most of these squigglies can be made to go away using the format command in your IDE, or by running pnpm lint:fix in your terminal.

Clean Code - TypeScript

Refactoring

Refactoring is a misleading term, as the factoring part needs to happen first.

Let's say we have:

c=x+xyc = x + xy

We can make it easier to read by factoring out the x:

c=x(1+y)c = x(1 + y)

This is great, and we can go even further:

c=x2(1x+yx)=x3(1x2+yx2)=x4(1x3+yx3)\begin{align*} c &= x^2\left(\frac{1}{x} + \frac{y}{x}\right) \\ &= x^3\left(\frac{1}{x^2} + \frac{y}{x^2}\right) \\ &= x^4\left(\frac{1}{x^3} + \frac{y}{x^3}\right) \end{align*}

Now compare the two equations, which one is easier to understand?

c=x4(1x3+yx3)c = x^4\left(\frac{1}{x^3} + \frac{y}{x^3}\right) c=x(1+y)c = x(1 + y)

Now take this concept and apply it to code. You'll find that the parallels are uncanny.

On this page

Made with πŸ’š for Hackers by Hackers