Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Nov 18, 2010, 03:43 PM   #1
robbo91
macrumors newbie
 
Join Date: Feb 2010
Learning Cocoa by Translating Code?

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?
robbo91 is offline   0 Reply With Quote
Old Nov 18, 2010, 04:21 PM   #2
lloyddean
macrumors 6502a
 
Join Date: May 2009
Location: 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.
lloyddean is offline   0 Reply With Quote
Old Nov 18, 2010, 04:25 PM   #3
PatrickCocoa
macrumors 6502a
 
Join Date: Dec 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.
__________________
iMac 21.5", 3.06GHz, 4 GB, 2 TB HD.
iPod Touch 3G.
PatrickCocoa is offline   0 Reply With Quote
Old Nov 18, 2010, 06:27 PM   #4
robbo91
Thread Starter
macrumors newbie
 
Join Date: Feb 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.
robbo91 is offline   0 Reply With Quote
Old Nov 18, 2010, 07:24 PM   #5
BadWolf13
macrumors 6502
 
Join Date: Dec 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.
BadWolf13 is offline   0 Reply With Quote
Old Nov 19, 2010, 02:26 PM   #6
mfram
macrumors 6502a
 
Join Date: Jan 2010
Location: 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.
mfram is offline   0 Reply With Quote
Old Nov 19, 2010, 03:01 PM   #7
whooleytoo
macrumors 603
 
whooleytoo's Avatar
 
Join Date: Aug 2002
Location: Cork, Ireland.
Send a message via AIM to whooleytoo
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.
__________________
Mac <- Macintosh <- McIntosh apples <- John McIntosh <- McIntosh surname <- "Mac an toshach" <- "Son of the Chief"
whooleytoo is offline   0 Reply With Quote
Old Nov 19, 2010, 03:39 PM   #8
ulbador
macrumors 68000
 
ulbador's Avatar
 
Join Date: Feb 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.
ulbador is offline   0 Reply With Quote
Old Nov 19, 2010, 05:12 PM   #9
PatrickCocoa
macrumors 6502a
 
Join Date: Dec 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.
__________________
iMac 21.5", 3.06GHz, 4 GB, 2 TB HD.
iPod Touch 3G.
PatrickCocoa is offline   0 Reply With Quote
Old Nov 19, 2010, 07:12 PM   #10
chown33
macrumors 603
 
Join Date: Aug 2009
Quote:
Originally Posted by ulbador View Post
... Everything in Java is an object, ...
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.
chown33 is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Learning to Code: Where to Start? ToomeyND Mac Programming 11 Mar 5, 2014 02:27 PM
learning x-code .. need advice ! rashidyn iPhone/iPad Programming 39 Apr 24, 2013 03:37 PM
App of learning counting in Multi-language (including Promo code) Magdalen iPhone and iPod touch Apps 0 Nov 13, 2012 04:51 AM
Learning to code... SR71 iPhone/iPad Programming 9 Oct 11, 2012 08:20 PM
Learning Code oxxygenn Mac Programming 3 Jul 19, 2012 10:15 PM

Forum Jump

All times are GMT -5. The time now is 08:24 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC