Question about the logic judgment of code programming specifications?

Source: Internet
Author: User
I would like to ask you a lot about how to optimize or circumvent such a phenomenon by referring to the code programming specifications?

I would like to ask you a lot about the logic judgment, but it seems too complicated.Code programming specificationsFor reference, howOptimizationOrAvoidanceWhat about this phenomenon?

Reply content:

I would like to ask you a lot about the logic judgment, but it seems too complicated.Code programming specificationsFor reference, howOptimizationOrAvoidanceWhat about this phenomenon?

Experience problems. Separately, if (! Is_array). This may come from the following requirements:
We have a number and want to compare it with another one. What is the other? You can enter the number at will, but it must be greater than 5, less than 7, about 8, less than or equal to 10, do it for you.
Then you did it. No error.
Because developers who do not understand development can describe their needs in a realistic manner, I think developers should have their own understandings. For example, I will abstract them:
Compare the number A with the expected expression B and obtain the result. Expression B contains the operator and the operand. That is, expression B should conform to the Regular Expression/^([^\d]+)(\d+)$/Where $1 is the operator and $2 is the operand. The operator must be <, <=,>,> =.
In this way, the code will be similar

// $ A operand A, $ B, expression B, $ c, operator, $ n2 second operand if (! Preg_match ('/^ \ d + $/', $ a) {die ('a invalid ');} if (! Preg_match ('/^ ([^ \ d] +) (\ d +) $/', $ B, $ _ match) {die ("format error ");} $ c = $ _ match [1] [0]; $ n2 = $ _ match [1] [1]; $ useableC = array ('<', '<= ', '>', '> ='); if (! In_array ($ c, $ useableC) {die ('invalid operator ');} eval ("\ $ t = $ a $ c $ n2 "); if ($ t) echo 'y'; echo 'n ';

Obviously, you can easily extend it to more operators, and then add = ,! = Very convenient.
The above is a pseudo code. We do not recommend using regular expressions as the final standard for digit validity verification.

The writing skills are poor. I don't know what you want to express. I hope it can help.

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.