The value of that strange Objective-C syntax

Discussion in 'iOS Programming' started by jiminaus, Nov 11, 2011.

  1. jiminaus macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #1
    I've gone over to the dark-side and am starting to do Android development, and with it I'm back to coding in Java.

    I've just coded the following line of Java.
    Code:
    getLoaderManager().initLoader(0, null, this);
    
    It made be realise just how the Objective-C style of method naming really makes code so much less enigmatic. If Android used Objective-C, the equivalent would be:
    Code:
    [self.loadManager startLoaderWithId:0 args:nil delegate:self];
    
    (I have to change init to start because init implies something in Objective-C that the Java code doesn't).

    I know a lot of new comers to Objective-C complain about the strange Objective-C syntax. But I hope this example highlights its advantage.
     
  2. Sydde macrumors 68020

    Sydde

    Joined:
    Aug 17, 2009
    #2
    Objective-C method calls are nearly self-commenting. The verbosity is a good thing– unless, of course, it encourages less // commenting.

    Can you compare performance? How well does the Java run compared to the same code in iOS?
     
  3. jiminaus, Nov 11, 2011
    Last edited: Nov 12, 2011

    jiminaus thread starter macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #3
    That's what I keep wanting to do in my Java code. The code itself isn't documenting what these vague arguments are, so I keep wanting to document that by putting comments after each argument. Before my exposure to Objective-C, I never had this compulsion.

    The Objective-C code was purely hypothetical.
     
  4. jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #4
    Thing is, like the guy in Stanford Video's says. is that they tried to make Objective C readability, as close as normal English as possible.
    Which is totally correct. if you literly read the lines, it's mostly easy to read through the code as a normal book. that's what I think is ObjC > other languages. Even though in beginning it's a tad confusing.
     
  5. Vizin, Nov 12, 2011
    Last edited: Feb 28, 2013

Share This Page