Is the reusability principle of this code good or bad?
- WBOYOriginal
- 2016-08-22 10:12:54928browse
Reply content:
Reliable code and DRY (picture is GacUI) - vczh's daily life - Zhihu column
If you go down a wrong path, turn back quickly.
Such code is complex, difficult to write, read and maintain, not to mention reusable.
I think the key to the problem is how detailed error handling needs to be.
According to my experience, it is not necessary to check every function called, especially in languages that do not optimize syntax for error handling.
So I think you only need to do error handling in functions that you think are likely to cause errors or must be handled when errors occur.
As for reuse, Don't repeat yourself is the key. If you have any doubts, just think over and over again how to abstract the code to a suitable level.
I don’t think it’s necessary to sacrifice readability for highly abstract code commonalities for reuse.
Before the requirements or problems to be solved have not been truly considered or studied clearly, it is difficult to make the code highly reusable and easy to read. Then first decompose the big problem into N sub-problems. Then, do TTD for the sub-problems, and then continue to optimize.
Code reuse in one step is not realistic.
It feels like looking at C code again. . Why not use the high-tech try catch throw instead of writing exception handling yourself. . .
Regardless of logic, just look at structure. Have you ever considered concurrency?
Uninvited, please refer to
http://zh-google-styleguide.readthedocs.io/en/latest/Google Open Source Project Style Guide
See more awesome open source projects
What the subject wants to do is actually Promise. Resolve is called successfully, reject is failed, and bubbling out is supported in case of exception. Externally, only then and catch chain calls are needed, which looks very elegant.
Every class must be written like this? What does this have to do with code reuse?Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn