When do I need to determine the return value of a function (method) during programming?

Source: Internet
Author: User
During programming, you must call functions or methods frequently. To ensure program robustness, you generally need to judge the return values of functions (especially for functions that return bool values ), but do I have to judge the return value every time I call a function? In this way, not only do you think it is cumbersome, but you will also get the program code... during programming, you must call functions or methods frequently. To ensure program robustness, you generally need to judge the return values of functions (especially for functions that return bool values ), but do I have to judge the return value every time I call a function? In this case, it is not only complicated, but also the program code is full of judgment statements. So I would like to ask when the return value should be determined when a function (method) is called, when is it not required? Thanks :)

Reply content:

During programming, you must call functions or methods frequently. To ensure program robustness, you generally need to judge the return values of functions (especially for functions that return bool values ), but do I have to judge the return value every time I call a function? In this case, it is not only complicated, but also the program code is full of judgment statements. So I would like to ask when the return value should be determined when a function (method) is called, when is it not required? Thanks :)

Looking forward to php7

Function test (int $ a, int $ B): bool {return $ a> $ B ;}

Yes. It's just a little worth the candle.
In the function, any unsuccessful processing throws an exception. You do not need to judge whether to call this function.

Php is a weak language. In the code, if (function_name ($ params) {} is usually used to determine whether the returned value is needed. There is no need to worry too much about it.

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.