cuHacking logocuHacking DevDocs

Coding Guidelines

Spaghetti belongs on plates, not in our codebase.

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.

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.

People before reading the Knowledge Base: 🐈

People after reading the Knowledge Base: πŸ…

Last updated on

On this page

Edit on GitHubMade with 🩢 for Hackers by Hackers