Goal C - What is the syntax?

Which syntax do you think is better / more readable?

if(!myViewController.view.superview)

or

if(myViewController.view.superview == nil)

Thanks!!

+3
source share
4 answers

Both are very close, it comes down to the personal tastes or standards of the conding project in question.

Speak! myViewController.view.superview, meaning "no superview", is very clear.

Saying myViewController.view.superview == nil means that supiew nil is also very clear.

I would prefer if I wrote in English, I would say:

if there is no supervisor then

I would not say

if the add-in doesn't work

, . , , .

+8

, .

+8
0

, . "foo == nil" ( nil == foo, , "=" ), . , nil.

, , , , , , , , , , .

- 0, ( , ), '!' , (, , "!", "" , Objective-C ).

, C , . , , - BOOL, , , BOOL , , . BOOL char ( ), - :

    - (BOOL)checkFoo {
  BOOL foo = [bar count]; // imagine count is > 255
    if(foo)
      [self doSomething];
    return foo;
}

256 BOOL (NO) , , ,

    - (BOOL)checkFoo {
  BOOL foo = ([bar count] > 0);
    if(foo)
      [self doSomething];
    return foo;
}

- (BOOL)checkFoo {
    if([bar count]) {
      [self doSomething];
      return YES;
    }
    return NO;
}

, , , .

0

Source: https://habr.com/ru/post/1714347/


All Articles