Several good habits you should develop when writing high-quality code

  I read a lot of articles recently and learned a lot; share some good habits of writing code

  • After modifying the code, remember to test yourself.
  • The method inputs are tested as much as possible.
  • Get the properties of the object, first determine whether the object is empty.
  • When modifying the old interface, consider the compatibility of the interface.
  • For complex code logic, add clear comments.
  • After manually writing the SQL of the code business, first take it to the database and run it, and also explain to see the execution plan.
  • After using the IO resource stream, it needs to be closed.
  • The code takes measures to avoid runtime errors (such as array boundary overflow, division by zero, etc.)
  • After writing the code, get some insights into the multi-threaded execution and pay attention to the issue of concurrency consistency.
  • Multi-threaded asynchronous priority considers the appropriate thread pool instead of new thread, and considers whether the thread pool is isolated.
  • Try not to make remote calls or database operations in the loop, and give priority to batch processing.
  • When calling a third-party interface, you need to consider exception handling, security, and timeout retry.
  • The interface needs to consider idempotence.
  • In the case of multithreading, consider linear safety issues.
  • Consider the problem of master-slave delay.
  • When using the cache, consider the consistency between the cache and the DB, as well as (cache penetration, cache avalanche, and cache breakdown)

Guess you like

Origin blog.csdn.net/qq_43562262/article/details/113000649