zoukankan      html  css  js  c++  java
  • GoogleStyleGuide 一个不错的开源项目. 不及格的程序员

    推荐一个大众化语言学习的站点: 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.
    

    南来地,北往的,上班的,下岗的,走过路过不要错过!

    ======================个性签名=====================

    之前认为Apple 的iOS 设计的要比 Android 稳定,我错了吗?

    下载的许多客户端程序/游戏程序,经常会Crash,是程序写的不好(内存泄漏?刚启动也会吗?)还是iOS本身的不稳定!!!

    如果在Android手机中可以简单联接到ddms,就可以查看系统log,很容易看到程序为什么出错,在iPhone中如何得知呢?试试Organizer吧,分析一下Device logs,也许有用.

    我的开发工具

    对于博客园里的网友,不敢称为叫"程序员"的人,你们攻击性太强,看来你们是不会想到我的用意的.园子里有不少人都非常喜欢Jeffrey,是因为它的第一版 框架设计 CLR via C#.
    可是从第一版到现在的第三版,没有看到真正底层的东西,内容仅仅是比MSDN文档更丰富一些,可能是我的要求太高了吧.
    也就是因为它很多时候会接触到微软开发人员,会经常聊聊某些问题而已,而它又将这些问题反应到书中.也许它就像一个小记者.
    它的年龄大我们不多,我的孩子与它小儿子一般大,如果我能向它那样出入微软与它们开发人员长时间交流,不仅仅会牛成它这样.....
    可是微软的开发人员不会扔太多时间在它这儿的.所以它会整天追着这个,赶它那个..屁颠个不停吧...
    而它的另一版被称为好书的 Windows核心编程,更是没有什么深度可言,仅仅是将windows提供的api,以及内核功能再重申了一遍.
    这些书对晋及编程知识是有些贡献的,再说一遍我不是在匾低谁,说说想法而已.

  • 相关阅读:
    【译】第26节---配置一对多关系
    【译】第25节---配置一对一关系
    【译】第24节---Fluent API
    pycharm 更改创建文件默认路径和修改字体大小
    软件工程----自我介绍
    课堂作业---读取文件实现求数组中所有子数组和的最大值
    实现数组中连续子数组值和最大
    android-----实现不两个不同的activity的跳转和数据传递
    android------解决editText只输入一行和textView不显示过多的内容
    android-------实现底部导航的模板
  • 原文地址:https://www.cnblogs.com/ioriwellings/p/2037518.html
Copyright © 2011-2022 走看看