views:

906

answers:

6

I want to do a little development in OSX and the iPhone. I've been a .Net/C# developer for years. I was wondering if there was anybody that had experience in both platforms that could tell me how they compare and contrast. I'd like to get an idea of what sort of learning curve I've got ahead of me.

Thanks,

Geoff

+16  A: 

First the bad:
I have done some Cocoa development in XCode. The first thing you will notice is that the IDE (XCode) isn't anywhere as intuitive, or nice in general, as Visual Studio. I really miss intellisense when working in XCode. The Apple developers will probably down-vote me for that statement. But coming from a .Net environment, that is what I really miss. So don't set your expectations too high and you won't be too disappointed. I am not trying to run XCode down, it just isn't as nice as Visual Studio.

Now the good:
The general architecture of a Cocoa project is very nice. I do wish .Net Winforms and WPF used MVC out of the box like Cocoa projects do. As long as you follow the MVC pattern you should do OK with your project. Everything I have done is in Objective C. You might pick up a book on that. I purchased Cocoa Programming for Mac OS X and thought it was pretty good. If you have any C in your background, it will look very familiar. From a C# prospective, the dot notation for classes is replaced with a message-sending notation similar to Tcl.

Get iTunes loaded on your machine and download the iPhone dev videos under iTunes U. You will also need to sign-up for the developer program at Apple and download the extra bits for XCode for the iPhone.

Hope that helps. I am by no means a pro Cocoa developer.

Jason Jackson
Xcode has autocompletion, just turn it on in the properties if it's not coming up at the moment. Xcode is different from VS but once I learned it well I find it's very good... and it's completely free.
Jason Coco
Autocomplete doesn't hold a candle to intellisense, and doesn't work well for me. Not trying to start a religious war - just trying to give a valid .Net developer perspective of moving in Cocoa-land.
Jason Jackson
I've been a .NET developer for years and i've come to like the autocomplete BETTER than Intellisence. Mainly because of the way it fills out the parameters and you can use CTRL+/ to scan through them.
Lounges
Yeah it's kind of a personal thing. I actually prefer Xcode to VS by far. And I had worked with VS for years before moving to the Mac platform. And I found the autocomplete to be nice in how simple and down to earth it is.
Jon Gretar
Jason, can you describe in what way Xcode's CodeSense isn't working for you? If you'd rather not do so here, file a bug or enhancement request at http://bugreport.apple.com/ and it goes to engineering.
Chris Hanson
I just had to come back here and add more as today i'm dealing with NCB files. This is where visual studio stores that lovely intellisence information for C++ projects. About half the time they corrupt themselves and stop working! Never had XCode do that to me!
Lounges
Wow, I really got you going Lounges. I was just trying to give an honest take on developing in .Net and moving to Cocoa, and the frustrations I faced plus the stuff I liked about Cocoa's MVC model.
Jason Jackson
@Jason Jackson, I don't think you really got him going... you made extremely subjective statements and then backed them up with more subjective statements. For instance, *why* doesn't Xcode's autocomplete "hold a candle to" VS's? I don't see any real differences between the two.
Jason Coco
I found the Code Complete in XCode works much better when you force yourself to learn the keyboard short cuts. It was a little frustrating at first but once I found those it became much more predicatble.
TheGeoff
+3  A: 

The big thing you have to always remind yourself, is that Cocoa just doesn't work the same way as WinForms. You're not going to find an "Event Handler" anywhere, even though you'll be looking for one! Not that WinForms is bad, but Cocoa is just a different paradigm.

Paul Betts
+13  A: 

I've been developing professionally with C# and .NET since beta 1. The XCode IDE is a completely different animal than Visual Studio. Initially you will feel very confused and lost. I'm still not totally satisifed with the UI (dear god give me a Solution Manager window and kill this split screen crap), however in no time you'll be just as productive and fast as in Studio. Documentation is comparable although i prefer the layout in MSDN.

As for Cocoa its generally easier to work with as a GUI toolkit than .NET. As stated above its a different mindset, however once you wrap your head around it you'll dig it.

While its not iPhone related, there are MANY similarities between Mac and iPhone development. You'd be doing yourself a favor to pickup the latest version of the Aaron Hillegass OSX book. Its pretty much the de-facto guide for writing any Cocoa software.

In summary... your going to be VERY lost and confused initially, but tough it out its worth it.

Lounges
+4  A: 

I'm pretty experienced in both, although I haven't done much C# code for a year or so. I went from Obj-C to C#, and I didn't have too much trouble. Obj-C code seems to me to be a little bit more informal and less rigid than C#; for example there are no typed arrays, and you don't have to worry about explicitly checking if an object is nil/null before calling a method on it. In general this is a good thing, since you can write more compact, elegant code (IMO). At the same time unlike C# you need to know the basic concepts of C programming to work with Obj-C, so you might want to brush up on things like pointers if you're rusty.

I think for the APIs you'll find that Cocoa is more suited towards desktop applications, rather than the enterprise as .NET is. For instance, where .NET has ADO.NET, the ReportViewer control, while Cocoa has Core Data, PDFKit and SearchKit.

Marc Charbonneau
+7  A: 

I've just marked this as a favorite, as I'm hoping more .NET+Cocoa guys chime in. I'm just starting (again) with Cocoa, and am so far loving it. (It helps that I'm working on 10.5, which allows garbage collection as an option.)

Some of the biggest differences I've noticed thus far:

  1. Yes, XCode is very different than Visual Studio. Others may deride the "split screen" nature, but I've found it quite intuitive once I wrapped my brain around it. Perhaps the biggest piece of advice I can give here is customize the toolbar, add the "Editor" button, and use said button religiously for code editing.
  2. The messaging syntax feels unfamiliar, but I suspect that's because I don't come from a Smalltalk background. (I hear -- though I haven't validated this -- that the concepts are very similar.) Apparently, as of 10.5, dot-notation and the notion of properties has been added, but Hillegass recommends against them. I say do whatever feels right. (I haven't gotten that far in the book yet, myself ... )
  3. The language is, for all intents and purposes, untyped. The pros here are that you can actually modify framework classes to suit your needs, and the messages will get resolved at runtime, allowing you a lot more freedom. The cons are that you may not find errors until runtime, and many of these errors don't behave the way .NET exceptions do -- that is, many of them don't cause a complete application halt when you fail to trap them. (Admittedly, there is @throw keyword; I've not gotten there yet either. :)) Another con is that Obj-C's concept of null (nil) can receive messages -- no NullReferenceException concept, either. Both of these can cause debugging headaches.
  4. Interface Builder is a whole new beast, compared to WinForms/WPF/ASP.NET designers. The concept of archiving up the entire UI, and having it not be code, is one of the harder concepts for many of us .NET guys to grasp. Nothing wrong with it, but we need to get our heads around it.
  5. Garbage Collection. As of 10.5, Cocoa and Objective-C both support either reference counting (retain/release/autorelease) memory management and automated garbage collection. Having just begun working, I can't detail too much of the guts of either, but while the GC is easier to use, you will have to manually specify it in your target options -- and your app will now require 10.5 or higher to run. Additionally, even with the GC, it's a best practice to manually set your pointers to nil when you're done with them, to hint to the GC that they may be ready for collection. Not quite as transparent as .NET. (Again, not bad, just different. Things to know!)

I am by no means an expert. I literally just started down this path myself (once again). I'm loving it, though, and I suspect that if a hard-core Microsoft development guy like myself can get to digging it, others can, too.

Finally, I discovered the .NET Addict blog a few months ago. The author does both .NET and Cocoa, and has several posts discussing the differences. Highly recommended.

John Rudy
+10  A: 

If you have some Cocoa/Objective-C background, then you can jump into iPhone development with the help of "Beginning iPhone Development" by Dave Mark and Jeff LaMarche:

http://www.amazon.com/dp/1430216263/

It's very easy to follow, but the authors assume some prior knowledge of Objective-C (as stated on the back cover), so I'd recommend starting with the first five or six chapters of "Cocoa Programming for Mac OS X" by Aaron Hillegass, as noted by others previously.

http://www.amazon.com/dp/0321503619/

Aaron has been using and teaching Objective-C and the frameworks now associated with Cocoa since his days at NeXT, and it shows. The material is really, really good.

While the bulk of the development techniques apply equally to the Mac and to the iPhone, some techniques apply only to the Mac (e.g., garbage collection, bindings, Core Data) and some apply only to the iPhone (e.g., multiple targets for one action).

If you want to pick up iPhone development really quickly and you're willing to invest some cash, Aaron's team can also teach you everything you need to know in a week, through classes at the Big Nerd Ranch. (The iPhone class always fills quickly, but if you happen to be in the Silicon Valley, there's still room in "iPhone for commuters" in January.)

http://www.bignerdranch.com/

(Click the classes tab for a schedule of what and when, including Ruby, Android, and more.)

While I personally prefer the options above, there are of course some free online options as well. Scott Stevenson has put an enormous amount of effort into Cocoa/Objective-C tutorials:

http://www.cocoadevcentral.com/

And Stanford has offered classes both in Mac development and in iPhone development, taught by Apple engineers, and has posted the class materials online:

Mac: http://www.stanford.edu/class/cs193e/
iPhone: http://www.stanford.edu/class/cs193p/

Lastly, it seems that developers who come to Mac/iPhone development with a Windows background try to avoid Interface Builder (IB) and instead build the UI in code. I understand why – IB doesn't lay out everything that's going on in a nice code listing – but I strongly recommend against this strategy.

Mac/iPhone development is all about minimizing code. The less code you have to write, the less you have to maintain, and the less chance there is for a mistake. IB is great for minimizing the code needed for the UI.

Your C/C# background will serve you well. You'll find that Objective-C seems quite odd at first, but I suspect you'll come to appreciate its strengths, and you'll pick it up very quickly. Unlike C++, it's actually pretty straightforward.

Glenn
Is this a precanned response, or did you write it for this post? You're working very hard for your upvote points :-)
Matt Gallagher
The Aaron Hillegass book mentioned is very good. I'm just learning Cocoa myself and it helped hugely. I've also read a couple of upcoming iPhone books (on Safari bookshelf) and while they were good in that they're iPhone specific, they don't contain nearly as much detail.
U62
+1 for the Great answer!
gyurisc
Hey, Matt — Actually, that was just for the post. :-) (And BTW, your CocoaWithLove.com site is bloody amazing.)
Glenn