Is it necessary to split and encapsulate the php method too long?

Source: Internet
Author: User
Ask if php's method body is too long. is it necessary to split and encapsulate it? if a method body is too long, is it necessary to split several internal functions and encapsulate the call? the premise is that the encapsulated method will not be reused. ------ solution ------------------ The problem is that the code is inconvenient to view, so I may split it several functional module files include. if you call these details elsewhere, it is necessary to split them into other units. this is my personal practice. --- is it necessary to split and encapsulate the php method too long?
If a method is too long, is it necessary to split several internal functions and encapsulate the call?
The premise is that the encapsulated method will not be reused.

------ Solution --------------------
The long problem is that it is inconvenient to view the code.
So I may split it into several functional module files: include.

If you call these details elsewhere, it is necessary to split them into other units.
This is my personal practice.
------ Solution --------------------
How many functions does one method need to complete? Obviously, it is to be split.
A function is a function. if there are several functions, there should be several functions.
At this point, there is no country difference




------ Solution --------------------
This can also be considered to have little to do with reuse. You divide long functions into several functions. It is easy to read and make it clear to others. In addition, you only need to modify it in a specific part. And mvc.
------ Solution --------------------
The encapsulated structure is clearer. Add comments. So that the maintenance will not be dizzy ..

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.