推荐一个大众化语言学习的站点: http://code.google.com/p/google-styleguide/
它使用xml+xslt的方式解析成HTML页面,并且循续渐近式的介绍每种(比较大众化的,目前收录了 C++ , JavaScript, Objective-C , 和Python )编程语言 .
可以作为内部培训资料或是初学者使用.
样例:
Background Objective-C is a very dynamic, object-oriented extension of C. It's designed to be easy to use and read, while enabling sophisticated object-oriented design. It is the primary development language for new applications on Mac OS X and the iPhone. Cocoa is one of the main application frameworks on Mac OS X. It is a collection of Objective-C classes that provide for rapid development of full-featured Mac OS X applications. Apple has already written a very good, and widely accepted, coding guide for Objective-C. Google has also written a similar guide for C++. This Objective-C guide aims to be a very natural combination of Apple's and Google's general recommendations. So, before reading this guide, please make sure you've read: Apple's Cocoa Coding Guidelines Google's Open Source C++ Style Guide Note that all things that are banned in Google's C++ guide are also banned in Objective-C++, unless explicitly noted in this document. The purpose of this document is to describe the Objective-C (and Objective-C++) coding guidelines and practices that should be used for all Mac OS X code. Many of these guidelines have evolved and been proven over time on other projects and teams. Open-source projects developed by Google conform to the requirements in this guide. Google has already released open-source code that conforms to these guidelines as part of the Google Toolbox for Mac project (abbreviated GTM throughout this document). Code meant to be shared across different projects is a good candidate to be included in this repository. Note that this guide is not an Objective-C tutorial. We assume that the reader is familiar with the language. If you are new to Objective-C or need a refresher, please read The Objective-C Programming Language . Example They say an example is worth a thousand words so let's start off with an example that should give you a feel for the style, spacing, naming, etc. An example header file, demonstrating the correct commenting and spacing for an @interface declaration // GTMFoo.h // FooProject // // Created by Greg Miller on 6/13/08. // Copyright 2008 Google, Inc. All rights reserved. // #import <Foundation/Foundation.h> // A sample class demonstrating good Objective-C style. All interfaces, // categories, and protocols (read: all top-level declarations in a header) // MUST be commented. Comments must also be adjacent to the object they're // documenting. // // (no blank line between this comment and the interface) @interface GTMFoo : NSObject { @private NSString *foo_; NSString *bar_; } // Returns an autoreleased instance of GMFoo. See -initWithString: for details // about the argument. + (id)fooWithString:(NSString *)string; // Designated initializer. |string| will be copied and assigned to |foo_|. - (id)initWithString:(NSString *)string; // Gets and sets the string for |foo_|. - (NSString *)foo; - (void)setFoo:(NSString *)newFoo; // Does some work on |blah| and returns YES if the work was completed // successfuly, and NO otherwise. - (BOOL)doWorkWithString:(NSString *)blah; @end An example source file, demonstrating the correct commenting and spacing for the @implementation of an interface. It also includes the reference implementations for important methods like getters and setters, init, and dealloc. // // GTMFoo.m // FooProject // // Created by Greg Miller on 6/13/08. // Copyright 2008 Google, Inc. All rights reserved. // #import "GTMFoo.h" @implementation GTMFoo + (id)fooWithString:(NSString *)string { return [[[self alloc] initWithString:string] autorelease]; } // Must always override super's designated initializer. - (id)init { return [self initWithString:nil]; } - (id)initWithString:(NSString *)string { if ((self = [super init])) { foo_ = [string copy]; bar_ = [[NSString alloc] initWithFormat:@"hi %d", 3]; } return self; } - (void)dealloc { [foo_ release]; [bar_ release]; [super dealloc]; } - (NSString *)foo { return foo_; } - (void)setFoo:(NSString *)newFoo { [foo_ autorelease]; foo_ = [newFoo copy]; } - (BOOL)doWorkWithString:(NSString *)blah { // ... return NO; } @end Blank lines before and after @interface, @implementation, and @end are optional. If your @interface declares instance variables, as most do, any blank line should come after the closing brace (}). Unless an interface or implementation is very short, such as when declaring a handful of private methods or a bridge class, adding blank lines usually helps readability.