"Tricks" of the "Trade"
"Tricks" of the "Trade"
- Subject: "Tricks" of the "Trade"
- From: Erik Thorteran <email@hidden>
- Date: Wed, 6 Jun 2001 17:15:40 -0700
I have a few general suggestions for Cocoa, OSX and programming in
general that I hope prove useful to some people, hopefully everyone has
a rich amount of suggestions to newbies, and veterans alike:
1. For NSArrays, NSDictionarys and their Mutable subclasses, use
[[ClassName alloc] init] as opposed to [ClassName arrayWithCapacity:4]
and their ilk, this tip has proved invaluable to my programs as it is
the only way to allocate them without a hitch.
2. Don't try to make things optimized on the first try! Check out my
single line of code that resulted from this:
[[[themeElementPieces objectAtIndex:j] lastPathComponent] stringByDeletingPathExtension]
,@"DName",
[DSBool bool:NO],@"isExpandable",
[NSArray arrayWithArray:contents],@"contents",
[NSString stringWithString:[[[[[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent]
stringByAppendingString:@"/Theme Elements/"]
stringByAppendingString:[prospectiveThemes objectAtIndex:i]] stringByAppendingPathComponent:
[themeElementPieces objectAtIndex:j]]],@"path",
[NSString stringWithContentsOfFile:[[[[[[NSBundle mainBundle]
bundlePath] stringByDeletingLastPathComponent]
stringByAppendingString:@"/Theme Elements/"]
stringByAppendingString:[prospectiveThemes objectAtIndex:i]] stringByAppendingPathComponent:
@"path.txt"]],@"prospecivePath",
nil] forKey:[NSString stringWithString:[[[[[[NSBundle mainBundle]
bundlePath] stringByDeletingLastPathComponent]
stringByAppendingString:@"/Theme Elements/"]
stringByAppendingString:[prospectiveThemes objectAtIndex:i]] stringByAppendingPathComponent:
[themeElementPieces objectAtIndex:j]]]];
YES! this is one line of code, technically. This line took HOURS to
debug. Blech.
3. Always start with small things. For something using (in end form)
only a window and a tableview, don't implement anything, just the Window
and TableView in the Nib file, see if it compiles and runs, and go from
there. Always small steps, it is much easier in the end.
4. Press shift while clicking the minimize button to get a slow motion
version (like Steve does in the keynotes. Press option while clicking
the minimize button to minimize all windows in the application (ditto
for the close buttons and zoom buttons). Press shift-close to make
windows dissolve and smear away (just kidding).
5. Comment code, always. You may notice that the aforementioned
single line of code has no comments, this is one of the reasons it was
such a pain to debug.
6. Use subroutines, even inline ones if necessary, it removes clutter
from each source code file, and spreads it out.
7. Use categories to extend features if possible, only use subclasses
if necessary.
8. Follow the Aqua Interface guidelines to create a good-looking
interface, it only adds to the user-frinedlyness of your program and OSX
in general.
9. Most important: pay shareware fees! (not that I have paid for
OmniWeb yet but...)
Hope these are helpful, and that more people will give their nuggets of
wisdom.
Erik Thorteran