About the judgment of writing code

I feel less and less able to write code. At present, there is a problem, that is, when does
need to be judged, and when is the judgment redundant and unnecessary?

for example,
1, do you judge the addition, deletion, modification and query of the database every time?
2. Do you judge the redis operation every time?

is there a more concise way to write about judgment? I really feel redundant to judge one step at a time.

Apr.01,2021

I think the judgment of the code will make it much clearer to grasp the relationship between levels. For example, if redis fails to instantiate, it will not do anything and return the result of fasle error, instead of not judging at the beginning and judging whether it is instantiated before each operation. In addition, judgment generally only judges the special situations that need to be dealt with, not all cases. For example, some requests for an API are correct only when errcode=0 is used, then when only errcode=0 is judged, a default error result is returned in other cases


multiple judgments are actually unnecessary, as long as there are no exceptions or code severity errors, the code can be executed sequentially. All need to use try {} catch () {}


this may need to be based on the needs of the actual application.


the landlord should have reached a new level. This is how to write beautiful code. I also feel that no matter how to write it now


in a business, if multiple sql or redis operations occur, it is recommended that you throw an exception and do not make a judgment


.

for example, if some requests for an interface are correct only when errcode=0 is used, then only errcode=0 is judged and a default error result is returned in other cases

mangafox

Menu