Now I feel that my code is very repetitive. Once the logic is complex, all the code is accumulated together. There is no way to separate them, which is not conducive to maintenance and expansion. How can we optimize it. Now I feel that my code is very repetitive. Once the logic is complex, all the code is accumulated together. There is no way to separate them, which is not conducive to maintenance and expansion. How can we optimize it.
Reply content:
Now I feel that my code is very repetitive. Once the logic is complex, all the code is accumulated together. There is no way to separate them, which is not conducive to maintenance and expansion. How can we optimize it.
If you do not talk about the theory, simply start with php:
-
We recommend laravel or symfony for learning php open-source projects. Strictly speaking, thinkphp is not object-oriented. The Recommended reason is that the Code is highly componentized (the written code is easy to share and reuse), and the support of various testing tools is very good.
-
Coverage testing. Common testing frameworks include phpunit, phpspec, behat, and codecept. It is very difficult to write good code at once, and experience needs to be learned from constant optimization. Code that does not write tests cannot be reconstructed. We recommend a simple and clear explanation of how to write a test slide:
Http://www.slideshare.net/cakper/2014-0407-php-spec-the-only-design-tool-you-need-4developers
-
Code writing follows the psr1/psr2 code standard https://github.com/pizzaliu/php-fig.
Http://www.zhihu.com/question/35992354
Reading books and improving the theoretical level.
Two books are recommended. Read the first book first and then the second one.
Enterprise Application Architecture Model
Http://book.douban.com/subject/1230559/
Implementation field-driven design
Http://book.douban.com/subject/25844633/
By the way, thinkphp is rarely used. The more skilled thinkphp is, the worse the code is.
First, select the right framework. laravel or yii is a good choice. Second, you think that the code is complex and the logic is repeated, which can reflect that the system architecture is no longer able to meet future business growth. The smelly and long business code should be extracted or independent, make good use of the architecture model or framework.