SaveText.Ru

Без имени
  1. hi everyone, my name is Anton, today we’ll talk about the quality of the code
  2.  
  3. 1.
  4. Code quality is a topic that was born with programming, but there is no exact definition and standard for code quality.
  5. Each developer understands quality in his own way, based on experience. Each team for individual projects evaluates the code in its own way.
  6. Clean code increases the viability of the project and lowers the threshold for entry.
  7. When new people appear on the team, they will ask fewer questions. In such a project, it is easier to attract developers due to the low entry threshold.
  8.  
  9. 3.
  10. Our code must be as clean and easy to read as possible.
  11. That is actually the art of programming – to take a complex task and code it in a way that is both correct and human-readable.
  12. A good code style greatly assists in that.
  13. There is such a term as a linear code - it is a code that can be read like a book.
  14. Linear code is read from left to right, from top to bottom, without having to return to the previously written code.
  15. The slide shows an example of linear code
  16.  
  17. 4.
  18. The slide shows an example of non-linear code
  19. No one likes to read a long horizontal line of code. It’s best practice to split them.
  20. The maximum line length should be agreed upon at the team-level. It’s usually 80 or 120 characters.
  21. There are two types of indents:Horizontal indents: 2 or 4 spaces.
  22. A horizontal indentation is made using either 2 or 4 spaces or the horizontal tab symbol (key Tab).
  23. Which one to choose is an old holy war. Spaces are more common nowadays.
  24. Vertical indents: empty lines for splitting code into logical blocks.
  25. Insert an extra newline where it helps to make the code more readable.
  26. There should not be more than nine lines of code without a vertical indentation.
  27. Function Placement.
  28. If you are writing several “helper” functions and the code that uses them, there are three ways to organize the functions:
  29. 1.Declare the functions above the code that uses them:
  30. 2.Code first, then functions
  31. 3.Mixed: a function is declared where it’s first used.
  32. That’s because when reading code, we first want to know what it does.
  33. If the code goes first, then it becomes clear from the start.
  34. Then, maybe we won’t need to read the functions at all, especially if their names are descriptive of what they actually do.
  35.  
  36. 5.
  37. What you need to consider in naming.
  38. 1.We use CamelCase notation: No transliteration, all method names are in English only
  39. 2.Bottom underline for private properties.
  40. 3.Constants in capital letters.
  41. 4.No one-letter variables.
  42. 5. Write clearly, that is, business functionally.
  43. There is no need to make the Check method, which checks something, but what is not clear.
  44. Write the spelling names of the methods.
  45.  
  46. 6.
  47. As we know from the chapter Code structure, comments can be single-line: starting with and multiline
  48. We normally use them to describe how and why the code works.
  49. At first sight, commenting might be obvious, but novices in programming often use them wrongly.
  50. But in good code, the amount of such “explanatory” comments should be minimal.
  51. Seriously, the code should be easy to understand without them.
  52. So, explanatory comments are usually bad. Which comments are good?
  53. Provide a high-level overview of components, how they interact, what’s the control flow in various situations…
  54. In short – the bird’s eye view of the code.
  55. There’s a special language UML to build high-level architecture diagrams explaining the code. Definitely worth studying.
  56. There’s a special syntax JSDoc to document a function: usage, parameters, returned value.
  57. Such comments allow us to understand the purpose of the function and use it the right way without looking in its code.
  58. By the way, many editors like WebStorm can understand them as well and use them to provide autocomplete and some automatic code-checking.
  59. Also, there are tools like JSDoc 3 that can generate HTML-documentation from the comments
  60. Summary: An important sign of a good developer is comments: their presence and even their absence.
  61. Good comments allow us to maintain the code well, come back to it after a delay and use it more effectively.
  62.  
  63.  
  64. 7.
  65. The first is Commitizen. This is a software utility that I learned about not so long ago -
  66. I looked, felt, liked it. It allows you to standardize message commits, has a nice console interface where you can select features.
  67. If you have commits in the spirit of “fixed a feature” or “fixed a bug”, then it's time to show Commitizen to your colleagues.
  68. Linters is a must-have tool in every project. There are many ready-made configs in linters, but you can write your own rules.
  69. If you have your own rules, then the linter should lint these rules - you will need to write the rules for your Code style.
  70. Useful links on the linter on the slide
  71.  
  72.  
  73.  

Share with your friends:

Print