Brent Simmons On Large Cocoa Projects

April 25th, 2007

Brent Simmons shares a good deal of wisdom in his post about managing a large-ish Cocoa project. In particular he’s referring to NetNewsWire, but his advice is especially pertinent to me now that I own and maintain a rather substantial number of source files that were designed and authored by Brent (MarsEdit, for anybody late to the party).

I love the emphasis on “researchability.” He points to the fact that projects of a certain size become impossible to keep in your head. So when you go to work on any particular subsection of the app, you need to be confident that you’ll find your balance quickly so you can get on with your work.

In particular, I liked the suggestion that weak binding in the form of notifications or key-value observing can be detrimental to researchability. Brent notes that the weak binding makes it difficult to mentally follow the source code, so it can be prudent to strongly bind classes that are otherwise useless without each other.

He also reminds us of some good IDE habits for maintaining code. I was glad to be reminded that the function popup in Xcode is keyboard invokable (as Brent says, “Every time you touch the mouse, God kills a kitten.”). This is very cool because with keyboard navigation of the menu you can quickly jump to a method by name.

Another tip he reminds us about is the “Open Quickly” option (cmd-shift-D). I use this feature frequently, but not in the way he describes. It’s infuriating that when you want to “open quickly,” the dialog for typing in the name of a source file doesn’t tab-complete. Imagine how much more powerful it would be if you could type “MyPic<tab>” and get “MyPictureThingyController.h”. Having to type the whole name of a file in removes most of the quickness. When I use the shortcut, I do so with the cursor inside the quotes or brackets of an include line. When invoked in this context, Xcode is smart and just jumps to the desired header file.

Update: Quentin over at Rogue Amoeba noticed this shortcoming a long time ago, and developed an Xcode plugin to address the problem. Check out Xcode Open Quicker.

13 Responses to “Brent Simmons On Large Cocoa Projects”

  1. Stephan Cleaves Says:

    I hadn’t known about the function popup being keyboard invokable either and that is going to be a nice addition to my workflow. I wanted to point out that “Open Quickly” will also work if you have a class name selected in the code itself. So a quick Option-Shift-Arrow and then Command-Shift-D will bring you to the header in question.

  2. Blake Seely Says:

    As far as “open quickly” goes, TextMate just KILLS Xcode. Same goes for navigating within a single file – TextMate can navigate methods and markers like no other program out there. TextMate is my tool of choice for research.

  3. charles Says:

    While we are on it, one thing I use all the time is command-double-clicking on a class name or a method, which jumps to the method header definition or implementation if available. I just mention it because it is so similar to cmd-shift-D.

    I hope this thread is not going to turn into a collection of cool Xcode tips… Well, why not?

  4. Conor Says:

    Ctrl-2 for the function list pop-up is a neat trick I was not aware of (#pragma mark – I picked up from the Cocoa mailing list and that makes the function list truly usable). When coding I use the regular Xcode view, however when doing the kind of research Brent mentions I spend almost all my time coding in the find window. It’s truly nice to be able to code directly in a split view and use command-e to see all the calls to a specific method and jump directly to them, even if I must kill a kitten to select the find result I want.

  5. Jacob Rus Says:

    Yeah, Blake’s right. Reading Brent’s discussion of keyboarding in XCode made me realize how much I appreciate TextMate.

  6. njyo Says:

    “I hope this thread is not going to turn into a collection of cool Xcode tips… Well, why not?”

    …well, if we are already on the way there: For me as a developer coming from the Java world (IntelliJ IDEA & Eclipse) one of the most annoying parts of XCode (well, it’s actually Obj-C, but XCode could help) is that refactoring of the method signature is a pain I have to do twice. Is there another way than Accessorizer to keep my .h files consistent to my .m files?

    Cheers,
    _Wolf

  7. Jens Ayton Says:

    Regarding command-double-click, a non-obvious feature is that if you command-double-click a function name where it is defined, it jumps to the declaration, rather than going for the definition of possible as it would otherwise.

  8. Steve Says:

    “Open Quickly” doesn’t tab-complete, but it *does* complete when you hit F5.

  9. Andy Lee Says:

    I only had time to skim the article (and other developers’ responses), but some great observations are made.

    Wrt to notifications, I feel the same way. I tend to be a late adopter of language and library features as I weigh them against any complications or non-deterministic behavior they may introduce in debugging.

    I believe Wil Shipley wrote something about not bothering to create frameworks out of common code libraries? I could be misremembering the author. I don’t have a link offhand, but I thought he was coming from a similar mindset.

  10. Andy Lee Says:

    Re: “researchability” — I do not have a great memory for code, and I am easily information-overloaded, so it’s extra important for me to design, code, and comment for my future self.

    I have source files grouped in directories. I keep meaning to put a small README file in each directory reminding me of the high concept behind those classes, and roughly how they work together — kind of like package.html files in javadocs.

  11. Andy Lee Says:

    Sorry, one more quick note before I have to run.

    The Ctrl-2 tip is going to be very helpful. Mousing through the function menu is a pain. I have asked for some kind of floating window or a pane like Eclipse uses so I can navigate to a particular method much of the time with one click and no dragging. While I’m waiting for that feature, I’ll have to see whether Ctrl-2 plus typeahead is satisfactory.

  12. Oskar L-B Says:

    Since tab-completion works with Cmd-Shift-G in Finder and Open/Save dialog-boxes, I wonder why they chose F5 in Xcode. (I’ve never seen F5 been used for that in _any_ app anwyhere before.) Being the consistency-maniacal Apple, they must have a very good reason…

  13. Wade Says:

    They chose F5 for completion because that’s the common key for completion in most Windows IDE’s.

Comments are closed.

Follow the Conversation

Stay up-to-date by subscribing to the Comments RSS Feed for this entry.