Google-StyleGuide 一個不錯的開源項目.

來源:互聯網
上載者:User

推薦一個福士化語言學習的網站: http://code.google.com/p/google-styleguide/

它使用xml+xslt的方式解析成HTML頁面,並且循續漸近式的介紹每種(比較福士化的,目前收錄了 C++ , JavaScript, Objective-C , 和Python )程式設計語言 .

可以作為內部培訓資料或是初學者使用.

範例:

BackgroundObjective-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 . ExampleThey 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; @endAn 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; } @endBlank 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.

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.