Bad taste of code: php code reconstruction (1. Preface)

Source: Internet
Author: User
As a front-end and php hacker, even mvc only stays in the state I have heard of. When I was just working on a website, the pressure was a little high. When I finally wrote it, the Code was suddenly written in a mess. A front-end page with a mix of php, js, and html code exceeded 1200 Lines. Long Ge said that the code is so arrogant that it cannot be tolerated as a person pursuing perfect code,

As a front-end and php hacker, even mvc only stays in the state I have heard of. When I was just working on a website, the pressure was a little high. When I finally wrote it, the Code was suddenly written in a mess. A front-end page with a mix of php, js, and html code exceeded 1200 Lines. Long Ge said that the code is so arrogant that it cannot be tolerated as a person pursuing perfect code,

As a front-end and php hacker, even mvc only stays in the state I have heard of. When I was just working on a website, the pressure was a little high. When I finally wrote it, the Code was suddenly written in a mess. A front-end page with a mix of php, js, and html code exceeded 1200 Lines. Long Ge said that the code style was so great that he could not bear to pursue perfect code, we can only refer to refactoring-improving the design of existing code at the bottom of a stack of books to start code refactoring.

First, analyze your own code:

At the beginning, I used the yii framework, which is an mvc framework. However, I only put the control code under the controllers directory and put the front-end view page in the views directory, as for models, haha, This is a magic horse ......

However, my database query functions and various processing functions are written in a func class and coexist in the controllers directory. This file contains more than 2000 rows ...... well, I can't bear to look straight at it. I also found many js functions in the front-end code, and repeated js functions on multiple pages, repeated css styles, and mixed php code. I can't bear to read this code, find out the problem first, and then refactor it step by step!


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.