How do you keep your code clean– For the front end

Time:2022-6-19

1. reduce repetition (style, variable, method, component)

Repeated code not only makes your project redundant, but also makes you gradually lose the concept of encapsulation.

2. delete redundant dead codes

Dead code is the code that will not be executed. For example, in the judgment if it will not go

3. vertical separation

Variables and functions should be defined near where they are used

4. avoid inconsistencies

For example, if res is used to accept the return value, then res is used in all projects

//Take a counter example
const data = response
const res = response

5. discard obscure intentions

The code should be as expressive as possible

//Take a counter example
const func = (n) => {
  const a = Math.radom() * 10 - 20 + 4 * (n + 1)
  return a
}

Although the code is short and compressed, it is difficult to understand. On the contrary, it makes the developer more confused about what he is expressing

6. follow standard dependency

Variable / constant naming, function naming, project structure

7. packaging conditions

Boolean values are difficult to explain and can be extracted for easy reference

  if (isNum(a)) {}

8. tool packaging

Public method set file, public style file, regular set file, etc

Recommended Today

P3120 [USACO15FEB]Cow Hopscotch G

portal ideas A simple idea is a\(O(n^2m^2)\)transfer of: \[f_{i,j}=\sum_{x=1}^{i-1}\sum_{y=1}^{j-1}f_{x,y}*[a_{i,j}!=a_{x,y}] \] There are so many constraints, thinking about using cdq divide and conquer to optimize we consider theRowdivide and conquer\([l,mid]\) Then brute force enumerationList,use\([l,mid]\)to update\((mid,r]\) enumerate columns each time\(j\)After the transfer, the\(\sum_{i=l}^{mid}f_{i,j}\)add to\(sum\), and update\(s[a_{i,j}]\)(used to subtract the contribution of the same number) The equation for […]