Learning Cocoa by Translating Code?

Discussion in 'Mac Programming' started by robbo91, Nov 18, 2010.

  1. robbo91 macrumors newbie

    Feb 11, 2010
    Hey guys. I've studied computer science at uni for one year with Haskell for first semester and java for second semester. In my second semester class, our major assignment was a computer game in Java using Jcomponent, Actionlistener etc.

    I've started looking into the C language and might move onto Objective C after that. I would like to one day translate the game I made into a Cocoa application. Could translating my existing code into Cocoa be a good learning experience or should I go a bit slower and learn other things first?
  2. lloyddean macrumors 6502a

    May 10, 2009
    Des Moines, WA
    If it motivates you to actually want to do the port and you complete it it's a start and I'd say yes.
  3. PatrickCocoa macrumors 6502a

    Dec 2, 2008
    Go Slower

    Go slower and learn what Cocoa and Objective-C are all about first. Depending on how much time you have, this may be a couple hours a day for about a month.

    Then take your existing code and try to translate it.
  4. robbo91 thread starter macrumors newbie

    Feb 11, 2010
    I have about 3 months of spare time depending on how much part time work I get, so I can spend a couple of hours a day learning stuff for a month, then get into programming fun stuff like games later.

    Thanks for the help guys.
  5. BadWolf13 macrumors 6502

    Dec 17, 2009
    I'm with Patrick on this one. I am a recent Obj-c learner myself, having come from a background that includes Basic, C, C++ and Touring. The hardest thing for me with Cocoa & Obj-C was not the actual language, which is really just a matter of terms and context, but the way that Cocoa does things, which put everything I'd done before out the window.
  6. mfram macrumors 65816

    Jan 23, 2010
    San Diego, CA USA
    I agree, the main problem with "translating" an existing app is not so much converting from Java to C/Obj-C. They are very similar syntactically. The bigger problem is that the design of Cocoa apps is very different than Java.

    You can hack your way through it for simple apps. But eventually you'll realize a Cocoa app probably needs a different design in order to be implemented effectively.
  7. whooleytoo macrumors 604


    Aug 2, 2002
    Cork, Ireland.
    If I were you, I'd just pick a relatively simple project, and try to do it in Cocoa. For example - one I did myself when learning - a iTunes-like media player. You would need to break this down into the tasks needed:

    - read a preferences file to get the location of your movies and song files.
    - scan that folder, to get an array of files.
    - Draw a list view, displaying that list of files.
    - Add a movie view, to play the movies.
    - Add play/pause/mute buttons, as necessary.

    Between the Apple Cocoa documentation, and the online tutorials for each, you should have little time learning the above, if you're patient and take it step by step. In doing so, you'll learn lots of other things - using NSStrings, how to use outlets and actions, the MVC architecture etc.
  8. ulbador macrumors 68000


    Feb 11, 2010
    I wouldn't necessarily do this. While java and Objective C are similar in many respects, they are also hugely dissimilar in other respects. Everything in Java is an object, where with Objective C, this is not always a case. The whole concept of ActionListeners and such is handled in a completely different manner than in Objective C. Even the basics of laying out a form in Java are wildly (and THANKFULLY) different in Objective C.

    As previous posters have mentioned, start with the basics and build up to the program instead of trying to directly replicate functionality. Even if you were porting the program and had experience in both languages already, you would probably still do things completely different because of how the languages differ.
  9. PatrickCocoa macrumors 6502a

    Dec 2, 2008
    I agree with myself

    I'll just chime in again to agree with my earlier post. And to clarify somewhat.

    You shouldn't try to port your current Java project into Objective-C/Cocoa AS A LEARNING PROJECT. As several others have said, particularly mfram, the design of projects is different in Objective-C/Cocoa. Once you spend a month or two on learning the basics with a smaller project or a set of tutorials, you can then take a whack at porting your Java project.
  10. chown33 macrumors 604

    Aug 9, 2009
    Sailing beyond the sunset
    This is incorrect.

    Java has primitive types as well as objects. The primitive types are: boolean, byte, char, short, int, long, float, double.

    In many cases the primitive types can and will be automatically boxed and unboxed (converted to and from object types), but this can also fail in certain subtle cases, so it pays to be aware of it.

    Java also has enum as a declarator for enumerated types.

Share This Page