• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Recommendation: Post *neat* code to this list
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Recommendation: Post *neat* code to this list


  • Subject: Recommendation: Post *neat* code to this list
  • From: Jerry Krinock <email@hidden>
  • Date: Tue, 23 Nov 2010 09:52:58 -0800

General recommendation: If you want people to read your code, please spend some time to make it neat and readable.  Stuff which is formatted like this:

@interface ComboscAppDelegate : NSObject <NSApplicationDelegate> {
	IBOutlet NSComboBox *countryCombo;
NSMutableDictionary *theCountries;
	NSMutableArray *myKeys;
	IBOutlet NSWindow *window;
}

or this:

@synthesize window;
- (void)applicationWillFinishLaunching:(NSNotification *)notif {
   theCountries = [NSMutableDictionary dictionaryWithObjectsAndKeys:
					 [NSMutableArray arrayWithObjects:@"AAABBB", @"AABBB", @"AAACCC", nil], @"A",
					 [NSMutableArray arrayWithObjects:@"BBBAAA", @"BBBBBBBB", @"BBBCCC", nil], @"B",
					 [NSMutableArray arrayWithObjects:@"CCCDDD", @"CCFGGGFF", @"CCCDDDFFF", nil], @"C", nil];

	myKeys = [NSMutableArray arrayWithObjects: [theCountries allKeys], nil];
}
@end

makes it look like like the author doesn't really care that much.  I've read that this list has thousands of subscribers; therefore when posting code you should value their time by spending little of yours, as though you were giving a presentation to thousands of people.

Apple's Mail.app indents a tab character by 8 spaces, so that if you copy code from Xcode, which you have typically set for 3-4 spaces per tab, you end up with indentations that are too large, as in the bad example above.  Since I post alot of code here, long ago I wrote a little AppleScript which processes the text on the clipboard, converting each of the tab characters inserted by Xcode into 4 spaces.  I set it as a menu item in QuicKeys.  You can put it in your Dock or other favorite app launcher.

Attachment: ClipboardTabsToSpaces.scpt.zip
Description: Zip archive


(P.S.  If the clipboard has alot of text on a slow Mac, wait a few seconds before pasting.)

Also, if some lines in the code are too long, shorten them by defining intermediate variables (and re-test before posting!).  I understand that modern compilers will remove such intermediate variables, so there is no performance penalty.

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Recommendation: Post *neat* code to this list
      • From: Mohsan Khan <email@hidden>
  • Prev by Date: Re: Radio dial buttons [iOS] -sheesh
  • Next by Date: Re: Recommendation: Post *neat* code to this list
  • Previous by thread: Custom table view cell
  • Next by thread: Re: Recommendation: Post *neat* code to this list
  • Index(es):
    • Date
    • Thread