The Unfamiliar (Objective-C & Cocoa)
daringfireball.net
daringfireball.net
XCode feels like a GUI for GCC, which it is. It's a whole pile of flags that you can set, tweak, etc. If you don't have some GCC experience, this is a bit of a hurdle. Project settings sometimes break (especially around code-signing), so keep your text editor handy. When things break the error messages can be cryptic and there's usually no 'double-click to get to the error in the IDE'. Obj-C is obviously C, but it's also obviously not and also not syntactically similar to, say, C# or Java (or Ruby, JavaScript, Python, etc). I found the step to Obj-C to be fairly trivial, but I thank time spent with C, GCC and Makefiles for that.
After this it's mostly the same as anything else - which is diving into massive amounts of APIs and best-practices.
iphoneos-simulator is brilliant. Much, much better to work with than Android simulators (mostly because of the insanely faster startup time and the ability to change hardware on the fly). Another brilliant piece to find was Instruments, which is an Apple GUI for DTrace. Profiling and tracing execution on simulators and devices is a breeze.
I think memory management is a bit of a non-issue and I'm surprised that's even being brought up. That many programmers only know one language / IDE and judge everything else as inferior/bad/etc is a reasonable observation (if not a totally obvious one), but that's not going to change anytime soon.
TL;DR
- XCode has warts
- Obj-C is different than Java/C#
- Errors can be a pain
- iphoneos-simulator is brilliant
- Instruments is fantastic
- Easy to pick up if you're familiar with GCC - XCode has warts: Yes, it does. Still, it is phenomenally better than other environments for efficiency now and is truly a joy to use. And we have few, if any, crashes.
- Obj-C is different than Java/C#: If you're familiar with one language, I can understand disliking that. I went from Java -> C# -> PHP -> Ruby -> Objective-C. That is quite a change! But still, I absolutely love Objective-C. It has everything I could ask for, including my favorite syntax ever created. Nothing is ambiguous to me and our team is able to crank from concept to MVP faster than any other platform by far. Better yet, the speed we can squeeze out of our code blows all other platforms away.
- Errors can be a pain: they can be. We ended up setting a standard syntax for logging actions so we could quickly drill down to errors. Wish it was easier and they can definitely improve here.
- iphoneos-simulator is brilliant: completely agreed.
- Instruments is fantastic: damn skippy.
- Easy to pick up if you're familiar with GCC: true.On the other hand, I'm rather surprised that Gruber is looking to defend reference counting, especially in light of how well it went for legacy programming languages like VB Classic.
John Siracusa is by far the more well-reasoned Apple advocate in terms of programming language design and his Copland 2010 articles are definitely worth checking out if you want to read a cogent argument as to why Cocoa is NOT the way of the future. http://arstechnica.com/apple/news/2010/06/copland-2010-revis...
I suspect that you're not up to speed on some things that were revealed at WWDC this year, because "reference counting" and "automated reference counting" are not the same things.
The latter is in the spirit of the last few paragraphs by Linus Torvalds in his famous 2002 discussion of Garbage Collection, when he says
Does it take more effort? Yes. The advantage of GC is that it is automatic. But CG apologists should just admit that it causes bad problems and often _encourages_ people to write code that performs badly.
I really think it's the mindset that is the biggest problem. A GC system with explicitly visible reference counts (and immediate freeing) with language support to make it easier to get the refcounts right (things like automatically incrementing the refcounts when passing the object off to others) wouldn't necessarily be painful to use, and would clearly offer all the advantages of just doing it all by hand.
http://news.ycombinator.com/item?id=2473932
...except ARC is better than Linus was imagining in the above, because it manages to do it without the "explicitly visible" part.
http://clang.llvm.org/docs/AutomaticReferenceCounting.html
Since you're a Siracusa fan...
http://arstechnica.com/apple/reviews/2011/07/mac-os-x-10-7.a...
I haven't read the article you're linking, but how does ARC manage to keep this invisible?
The usual trouble is supporting legacy code. Even with C++/Boost, where there's a variety of _ptr templates each promising either automatic deletion or automatic reference count decrement at an appropriate time, you can find yourself in a situation where there's a legacy C function accepting and returning, say, wchar_t*. You simply cannnot avoid doing malloc/free or retain/release in this situation.
Use of (automatic) reference counting is not new (see, for obvious example, Python), and is certainly being used as a form of garbage collection.
There are many forms/strategies of garbage collection, reference counting is one of them. Trying to argue that we're never going to have "garbage collection" on iOS is utterly bizarre -- it's being added in iOS 5! It's just taking a different form.
All those terms sometimes get used differently in different contexts sometimes, but I think that's what's usually meant by them.
Some interesting references:
http://en.wikipedia.org/wiki/Garbage_collection_(computer_sc...
http://www.research.ibm.com/people/d/dfb/papers/Bacon01Concu...
http://www.google.com/search?q=garbage%20collection%20refere...
This requirement that the application programmer participate in memory management contributes more to the distinction than the fact that the Cocoa reference counting scheme imposes less runtime overhead than most robust garbage collectors of the sort used by Java or Python.
The new Automatic Reference Counting used by Cocoa is still different from traditional garbage collectors, because it is implemented without imposing any more runtime overhead than the manual scheme. ARC is essentially a preprocessor phase that infers (based on coding conventions) where to place the calls to -retain and -release. None of the complex logic for tracking the lifetime of an object is done at runtime. It's done at compile time, if at all. (ARC differs from full-fledged robust garbage collectors like what Java has in that ARC can't handle situations like cycles in the object graph. Handling those cycles is one of the main things that makes writing a high-performance Java-like GC non-trivial, but ARC simply chooses to not be that automatic.)
Did I just step into the twilight zone?
Personally I really enjoy working in Objective-C and Cocoa/Cocoa Touch. I think they both hit sweet spots in language/framework design and give you just enough high level abstractions to make developing easier without getting in the way. But then again, I program in C for fun :-)
And Siracusa has been trotting out his pet theory about Objective-C/Cocoa being a dead end for years now. All of the articles he's written on the subject have made it clear that a) he has essentially no experience with the subject he is trying to discuss, and b) he's really, really bad at predicting the future of Apple's development landscape.
Since his first article calling Objective-C/Cocoa a dying platform, we've witnessed the introduction of an entirely new platform based on them (iOS), an enormous surge in usage and demand for Objective-C talent, and massive overhauls in the language (Objective-C 2.0) and memory model (first a conservative garbage collector, and now ARC). Siracusa has been out to lunch on the subject for years.
Likewise, GC may be able to deal with messy situations (ones that I'd advise you avoid anyway), but brings problems too like non-deterministic lifetimes. ARC isn't a silver bullet but I think it gets pretty close to how people use GC in day to day software.
Also, one of those "messy situations" that you'd advise us to avoid is the nigh-ubiquitous Cocoa controller-delegate pattern. That's a circular reference. With ARC, you have to explicitly break it. It's not a big darn in general, but it's a definite weakness of retain counting.
My point is that it's a massive hyperbole to call ARC "garbage collection without any of the nasty downsides."
Delegation patterns are complex for lifetime management though that is why they have spent a good portion of their documentation on helping people understand when to use zeroing weak references which is a very easy fix for problems like this. Their heuristics work better than I imagined here. Still trickier than GC but much more consistent.
So far the downsides are pretty small relative to manual memory management and close to GC without trading off the consistency of manual memory management. I'd say "garbage collection without any of the nasty downsides" is more accurate in this case than not.
Well, let's just say that I would be a very, very happy man if the Android emulator could run even 50% as fast as the iOS Simulator.
Yes, there are a lot of people who turn their nose up at the OS X/iOS development toolchain simply because it is unfamiliar. They see the square brackets and write it off immediately.
But the argument that the toolchain is not polished is dead on. If you look at the work Apple are doing under the hood with LLVM etc., then yes, they are doing some very smart things. But everything on top of that is pretty damn dismal. Xcode is incredibly buggy. iTunes Connect is hell. There is functionality that is just plain wrong. There are features that are inexplicably missing. Version control integration is so poor everybody I know uses external tools instead. Code-signing is held together with bits of string. Functional regressions from earlier versions mystify me. Xcode build configuration is so much of a hassle that it's easier to avoid it altogether by putting everything into xcconfigs. The code quality in the templates is awful.
If this kind of quality were foisted on end-users, there would be uproar. It's the opposite of Apple's "just works" philosophy. It seems the application-level dev tools team is where they stick all the students and new hires who don't know what they are doing.
I think the fundamental design of Objective C is a little old in places but has held up remarkably well over the years. Cocoa has a fantastic design. But christ, the development tools at the application level are a fucking embarrassment.
Until you get beyond the unfamiliarity, you're not qualified to judge if it's wrong or right.
(That said, the 2 hours I've spent in Visual Studio was remarkably pleasant, considering)
In other words, there's a lot of pain, currently, surrounding the de facto tool for iOS development, even for seasoned Cocoa programmers. It's too bad the original story (the one Gruber's responding to) got so off track talking about other nonsense (reference counting?! Does that objectively really matter?) when there are so many real problems that actually exist with iOS development.
Thankfully, these problems aren't necessarily permanent -- just as long as Xcode 4 continues to get refined/fixed, and documentation is brought up-to-date (i.e. no more Core Data how-to videos that use Xcode 3 on OS X 10.4!).
Having said that, they all have pretty crappy editors.
I think I'd have to agree with this statement. As someone who's recently started developing in Objective C and coming from a Java / Eclipse background, the toolset provided in Xcode seems to fall short of what Eclipse has to offer (I can't speak for Visual studio).
For instance I don't think Xcode does proper static analysis. I.e. it doesn't allow me to produce a proper class hierarchy for a class I'm using, nor can I run a command to see a call hierarchy on a method. And refactoring isn't 100% accurate either, and also very limited, i.e. I can't extract methods from a code fragment, and also once extracted, move that method into another class without issue (typical workflow for extracting helper methods).
It's not to say I can't do good work in Xcode. I just have to be aware of it's limitations and keep accurate documentation as I code, instead of relying on the IDE for a lot of the heavy lifting.
Then the iPhone came out...
ARC isn't a revolution, it's just a stage in a cycle....
In 10 years your 20 core smartphone will have a GC running in it.
Quite possibly. But it's also quite conceivable that Objective-C will still be in use by then, and still not have the what a Java programmer would think of as garbage collection. When iPhone hardware is ready for it, we'll probably see Python or MacRuby or JavaScript become the most common way of interacting with a Cocoa system that is still implemented in Objective-C.
It is amazing how predictable humans are, and how far people will go to exploit that predictability:
1. Draw line in sand. 2. Throw rocks at both sides. 3. Profit.
Gah - I was with you through the article, maybe not agreeing with everything he said, but did he have to come off like such a jerk in the last sentence? You're painting with pretty broad strokes to call people who aren't very enamored w/ XCode "offended" and "entitled."