"Reading note One", Zen and the Art of Objective_c craftsmanship

Source: Internet
Author: User

"Zen and the Art of Objective_c craftsmanship" is a book on Object_c optimization, a bit like the 52 effective ways to write high-quality iOS and OS X code in effective OBJECTIVE-C 2.0 , but shorter than the latter, with only 98 pages in all, and a booklet that takes hours to read. Although the volume is small, but the content is very practical, the following is my reading notes.

1, conditional statements are enclosed in curly braces, even if there is only one sentence, because this is easy to read and easy to maintain. Such as:

Suggestions:

if (! error) {  return  success;}

Not recommended:

if (!error)  return success;

2. If there is an equivalent comparison of conditional statements, it is recommended to put the constants on the left side, because this avoids the mistake of writing an assignment statement. Such as:

Suggestions:

if (5 = = myvalue) {    ...} or if ([myvalue isequal:@5]) {    if (nil = = myvalue) {    ...}

Not recommended:

if 5 ) {    ....} or if ([@5  Isequal:myvalue]) {    ...} or if (myvalue = = nil) {    ...}

Since nil is equivalent to No, the decision to nil can be made directly from a non-statement, which can be simplified as follows:

if (! myvalue) {    ...}

At the same time, the author also suggested that the judgment statement if the true and false judgment as little as possible with yes or no, because Yes and no in object_c defined as 1 and 0, and bool is unsigned char type, so:

Suggestions:

if (someobject) {... if (! [Someobject Boolvalue]) {.... if (!someobject) {....

Not recommended:

if (Someobject = = YES) {.... if (somevalue = = NO) {...

PS: Not to be continued .....

PSS: The book's

English version: Https://www.gitbook.com/book/yourtion/objc-zen-book/details

Chinese version: Https://www.gitbook.com/book/yourtion/objc-zen-book-cn/details

  

"Reading note One", Zen and the Art of Objective_c craftsmanship

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.