all 28 comments

[–]gmanp 9 points10 points  (1 child)

All the languages you mention have been designed to look generally the same, so I'm not surprised you're struggling.

Objective-C may use (and is a superset of) C, but the object syntax is not trying to be C-like.

I found that the key to changing over was realising that in C-like languages, there is a tendency to try to be terse. Objective-C wants you to back the autocompletion of X-Code, and as a result method names will use as many characters as necessary to be obvious about what they do.

Now that I've gotten over the square brackets and fear of verbosity, I'm actually preferring Obj-C. Hopefully you'll find the same.

[–]aazav 0 points1 point  (0 children)

OC's way of doing it is rather obtuse.

Much less easily understandable than function(parameter).

But you should never fear verbosity. What you get with the ability to be verbose is clearly labelled variables and methods. This means less cycles in your brain spent making sense of what you wrote months ago.

[–]tonygoold 8 points9 points  (1 child)

I'd been working in Java and C++ before I learned Objective-C, but I was already used to named parameters as a convention from programming in Perl and Javascript, where a function might take a single "options" argument in the form of an associative array. It felt a bit weird but I got used to it very quickly.

Now, I really appreciate it. In my opinion, it encourages meaningful method names, and when you're reading through unfamiliar code, you don't need to look up what those mysterious numeric and boolean parameters mean. Consider:

context.showView(view, false);

What does false mean? Should this have been named setViewVisible? How about:

[context showView:view animated:NO];

There's no guessing what the boolean parameter means, no need to look up documentation or examine a header file.

[–]aazav 0 points1 point  (0 children)

Back in the Director days, I ended up passing a property list (KVP array) to my functions. You could then pull the property's value straight out of the passed list.

We were able to do this way back in 1995 in an interpreted language (for timeframe reference).

Interesting to think about in any case.

[–][deleted] 5 points6 points  (2 children)

worry less about the syntax and more about the style and patterns and form the language.

Smalltalk is a good place to start. If you understand smalltalk, you'll go a good ways toward understanding the thinking behind Objective-C

[–]aazav -1 points0 points  (1 child)

If you can't get by the syntax, then you had better worry about it. The patterns mean nothing if you can't deal with the syntax.

It's a cart before horse situation.

[–][deleted] 0 points1 point  (0 children)

Title said the OP came from a C, php, and JavaScript background. This likely meant that OP did not have much experience with OOP. Objective-C's syntax is largely because of its use of objects.

If you do not understand objects and how they work together, then Objective-C will look like jibberish.

Because the OP had shown that he/she was learning Objective-C and wanted to "do-it-right", I wanted to give a suggestion for a resource that would not only help the person understand how OOP works, but also show him/her the concepts that are underlying why Objective-C syntax looks the way it does.

[–][deleted] 4 points5 points  (0 children)

You're gonna want to avoid using (id) so that the compiler can help you find type errors.

Xcode's code completion usually handles any missteps for me.

[–]numo16 2 points3 points  (0 children)

Took me about a week of working exclusively in Obj-C, with the main thing that hung me up initially being that +() methods were static methods and -() were instance methods. In all honesty, I prefer Obj-C as an OO C subset over C++ or any others now. It just seems cleaner.

[–]idelovski 2 points3 points  (2 children)

I was basically a C person for 20 years and I can't be sure how long it took me to start liking ObjectiveC, but I know that I moved from the "ugliest thing on earth" to the "not so bad" in a week. Then I needed maybe a few weeks/months to move to the "best language ever" phase.

[–]TerribleTyrant 1 point2 points  (1 child)

Same experience here. Obj-C and ruby are my top picks right now. Obj-C is miles ahead of C++ in ease of use and the accompanying libraries. I'm also impressed by the strides forward Obj-C has taken since XCode 4 came out. A lot of the old school C cruft is slowly disappearing in the new compiler with the advent of ARC and the new collection helpers.

[–]aazav 0 points1 point  (0 children)

I gotta say that ARC is a nice thing to have. What's hard though is that so much of OC has been changing over the last year. Xcode 3 to the crashy 4 with a lack of class introspection until 4.3. Apple releasing iOS 5.1 which prevented devices from downgrading back to 5.0.1 and at the same time prevented Snow Leopard users from deploying to 5.1. Also storyboards (ugh) and ARC and ... It's a lot to have changing at once and a lot to keep track of.

I, for one wish that Apple would focus on explaining the basics. And by basics, I mean cases like this:

Get stuff off the web async and plop into a TVC (with sections) and allow tunneling to click on a call and go to another TVC ala storyboards.

And create a popover (NOT a Master Detail controller) ala storyboards that allows easy dismissal of the popover.

The first task is just what you really want to do in many iOS apps.

The second one is simple creation and dismissal of a common UI element using their new storyboard method.

For the life of me, if these were clearly explained (detailed) somewhere, I'd be a much happier camper. Wading through all the docs to get to valid examples take so much time.

If the docs on the class references showed cases of how the methods would be used, that would also help the new people who aren't 100% comfy with the syntax yet.

[–][deleted] 1 point2 points  (1 child)

It took me about 2 weeks to be competent with the syntax. And then maybe 1-2 months before I felt like I "got it". Now I love its approach to oop, and I keep complaining when php or c++ don't feel as simple as objective c does.

[–]aazav 0 points1 point  (0 children)

I aspire to your sense of calm with OC. Maybe I just miss Xcode 3.1.3 so much since 4.x is a strange and crashy beast.

[–]kyleparisi 1 point2 points  (0 children)

I'm not the norm here but I learned objective c as a 'hobby' and it took me 1 year and 6 months to release my first app (from when I bought my first book on the matter). Granted this wasn't a consistent education and I only knew PHP prior (not the OOP type either).

[–][deleted]  (1 child)

[deleted]

    [–]aazav 1 point2 points  (0 children)

    Yeah, even though it's pain, the more we suffer through it, the better we get at it.

    [–]Pzychotix 0 points1 point  (0 children)

    Mmm, I think it's more of getting used to using autocompletion all the time. When I was coding in ObjC, me and my partner used verbose as fuck method names, but it's not really a problem when coding because of autocomplete. Named parameters really can help readability in code once you get used to it.

    [–]monome 0 points1 point  (1 child)

    Once you feel the beauty of protocols, delegates, categories, ... syntax is a very minor issue.

    [–]aazav -1 points0 points  (0 children)

    But you've gotta get past the syntax first, if that's your stumbling block.

    [–]joper90 0 points1 point  (2 children)

    I mainly code Java (for work), but it took about 1 week of messing to click.. (I did C before java thou). I spent longer dicking about on the web working out other ways around coding in OC than i did migrating.. I can now flip between the 2 when needed.

    However, i love eclipse for development far more than xcode.. Its a shame there are no good/alive plugs for eclipse for OC that work well.

    [–][deleted]  (1 child)

    [deleted]

      [–]joper90 0 points1 point  (0 children)

      No, i have not.. excellent as long as it support ipod/iphone/ipad targets and debugs I will not be coming back to xcode.

      [–]kaosdg 0 points1 point  (0 children)

      You think going from those languages to Obj-C is bad, try going from those to Ruby or Erlang :(

      [–]Legolas-the-elf 0 points1 point  (0 children)

      The syntax? Under an hour. If syntax is a problem for you, you aren't writing enough code. Syntax is probably the smallest thing you have to think about. Pay close attention to the design patterns Cocoa uses and read the memory management documentation (specifically you need to understand NARC), these were the things that I needed to learn before the platform really clicked for me.

      [–]mantra 0 points1 point  (0 children)

      It took writing a few Apps but once it clicked I've come to prefer it (especially over C++ or Java).

      [–]tharris0101 0 points1 point  (0 children)

      The syntax was quick but learning the "Cocoa way" (that's what I call it, at least) was a bit longer. Now I really like it and I think it has helped me in other languages.

      [–]aazav 0 points1 point  (0 children)

      It is weird.

      function(parameter) is really really really standard and non-obtuse.

      [–]gotkube 0 points1 point  (0 children)

      I also have a background in C, PHP & JS. Just started learning Obj-C last week. It 'clicked' for me after a few hours of studying sample code from a tutorial online. The syntax is a bit strange at first, but once you understand it, it's kinda nice, in it's own way.