1. Home
  2. /
  3. Gyan
  4. /
  5. Higher Quality Code should...
Higher Quality Code should have

Jan 4, 2023

  1. Comply business logic.
  2. Short.
  3. Understandable.
  4. Break down into function/components.
  5. Have common utility.
  6. Reusable.
  7. Documented.
  8. Good to have unit tests.
  9. Reformatted.
  10. ES-Lint should be enabled.
  11. File size should not be more than 500 lines.
  12. Using sonarlint, can easily maintain and remove cognitive complexity of functions and unused items.
  13. We should also focus on optimization of code, some time for getting desired result we use so much loops and conditions.
  14. Before using any npm package check weekly downloads and last update.
  15. Check build size as well before selecting any npm packages.
  16. Always validate the request you get.
  17. Always do a null check.
  18. Proper logs should be there for dubugging
  19. Code should be maintained easily.Future maintanence and feature addition can be done easily.
  20. Do file indexing inside folders that reduce multiple imports and keep everything in single import.
  21. Name convention (eg. Function name should be in camel case).
  22. Write unit test cases for each and every scenario.
  23. Could use lint-staged and husky hooks on commit to avoid conflicts of code format keeping code consistent across the team.
  24. CI/CD should be implemented to avoid build errors on daily basis.
  25. Create proper ReadMe file for better future use.
  26. Use .env / avoid hardcoding.
  27. We can use some predefined functions as per requirements instead of some algorithms, loops and logics, it can reduce our script time.
  28. Also we can use proper variable name, form field name, array name and function name as per our functionality so that one can understand which functionality comes under the function.
  29. We can follow the same name form field name and variable name and database column name which can be easy to remember while we are coding.
  30. Always beautify code.