PHP Code farming balance-write code speed, code execution efficiency, log statistics, error handling, etc.

Source: Internet
Author: User
PHP code balance-the speed of writing code, Code execution efficiency, log statistics, exception handling, etc.

Recently, I wrote in the most rigorous way for a period of time code, found that the speed of writing code has been reduced a lot, get the code is normative, rigorous (parameters, output judgment, exception handling), readability (a lot of comments), complete test cases,

With more and more experience in writing code, time is getting longer and more and more and more and more and more and more of the code cleanliness .

    1. See the code in the non-standard place always want to change (tab to space, using UNIX line break),
    2. No commented code, always to see who the author is, and then quietly despise, and remind yourself to write a good note (by this disgusting)
    3. A function does not validate the parameter and the return value, which is like a bare-Ben.
    4. If all public functions in a class have a complete test case plus a demo, this class makes it very comfortable for others to use (Hey, copy the demo directly to modify, you can easily call the class, colleagues can also test ha!). )
    5. No exception handling function, do not know when the crash.
    6. Without the log processing function, the program crashes and does not know where it was caused.

The ideal is very plump, the reality is very bony feeling:

The reality is that the leader urged to code on-line, found that the code has not yet finished writing, suddenly found to write PHP code exactly how rigorous? Can you sacrifice the rigor of a part of the code in exchange for the efficiency of writing code? Because leadership is the rigor of your code's test cases, lots of annotations, readability, exception handling, and so on. They are more concerned about the efficiency of writing code and the code is not a bug.


In response to this problem, my current solution:

Estimate the length of the project, about what kind of program can be written out?

Find a balance between the speed of writing code and the efficiency of code execution, log statistics exception handling, and so on:

You can reduce the code's comments appropriately,

Then the sequence is demo, test case, exception handling, log record, exception handling,

After the code, such as the normative, input and output judgment must not be less, these if less, but also write a code? After the basic completion of the project, you need to slowly add the missing things back.

As the coding becomes more efficient, the rigor, readability, and so on of the code will slowly merge into the code and quickly write more and more perfect programs.



1 floor CHENFANGLINCFL17 minutes ago
It's important to read the code
.
  • 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.