Android journey 1@关于编码风格和命名规范
/*
* 1.关于编程风格:每一位程序猿可能都有自己独特的编程风格,但是有些规则是大家都必须遵守的,特别
* 是在工作的过程中,良好的代码风格能大大提高代码本身的可阅读性和维护性,也更有利于别人修改你
* 的代码。风格问题涉及到的都是细节相关的问题,读者朋友们或许都听过“细节决定成败”这句话,这句话
* 在这里同样生效,不过是换了种意思,就是“细节体现你的专业程度”,所以作为一名程序猿,我们应该从
* 编写代码的训练中养成良好的编码习惯,如命名规范,排版规范,写好注释等。下面具体说明下:
*/
/*
* 1)整个Project相关内容的目录规范:(通常可以包含以下几个文件夹)
* #.Requirement Doc: project的需求文档说明
* #.Design:有关设计方面的说明
* #.Planning&Log:计划、日志、会议等
* #.Test:测试及其报告
* #.Study:学习资料及demo
* #.Deployment:发布,部署
* #.src: 源代码
* #.help:帮助文档
* #. ...(根据自己需求添加合适文档)
* 注意事项:在IDE建立project的时候,包即目录(java),包名全小写,且一般不超过3层,命名为:【公司】.【项目】.【模块】
*/
/*
* 2)命名规范:
* #、Pascal命名法:每个单词首字母大写,其余小写,如“ActivityDemo”,主要应用于:文件名,普通类名,构造函数等
* #、Camel命名法:第一个单词全小写,其余单词按pascal命名,如“myName”,主要应用于:方法名(动宾短语),普通函数名等
* #、匈牙利命名法(使用前缀,后缀命名):如对于整型变量,可以“int intMyAge;”
* #、下划线命名法:主要在常量(全大写)中使用,分隔两个不同单词
* 其他常见命名:私有成员变量:“mMyName”;静态变量:“sMyName”;方法参数:“pMyName”;
* 当然命名规则的使用主要看已有项目的要求,若新启动一个项目,编码前团队必须先统一命名规范
*/
/*
* 3)其他需要注意的地方:
* 1、一个方法不超过35行代码
* 2、不要去修改机器自动生成的代码
* 3、final String取代String,即不要直接写字符串
* 4、循环语句中不用return
* 5、属性用set(),get()方法操控
* 6、不要再系统生成函数中写复杂代码,复杂代码通常用函数调用解决
* 7、虽然class能搞定一切,但使用接口暴露信息会更好
* 8、switch语句中无论如何都要有default
* 9、同类的import包放在一起
* ...
*
*/
//下面看一下Android源码中的代码: /*
* Copyright (C) 2006 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/ package android.app; import com.android.internal.app.ActionBarImpl;
import com.android.internal.policy.PolicyManager; import android.os.Build;
import android.os.Bundle;
import android.os.UserHandle;
import android.text.Selection;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.text.method.TextKeyListener;
import android.util.AttributeSet;
import android.util.EventLog; /**可在注释中嵌入HTML标签,在生成javadoc的时候控制各种属性等
* An activity is a single, focused thing that the user can do. Almost all
* activities interact with the user, so the Activity class takes care of
* creating a window for you in which you can place your UI with
* {@link #setContentView}. While activities are often presented to the user
* as full-screen windows, they can also be used in other ways: as floating
* windows (via a theme with {@link android.R.attr#windowIsFloating} set)
* or embedded inside of another activity (using {@link ActivityGroup}).
*
* There are two methods almost all subclasses of Activity will implement:
*
* <ul>
* <li> {@link #onCreate} is where you initialize your activity. Most
* importantly, here you will usually call {@link #setContentView(int)}
* with a layout resource defining your UI, and using {@link #findViewById}
* to retrieve the widgets in that UI that you need to interact with
* programmatically.
*
* <li> {@link #onPause} is where you deal with the user leaving your
* activity. Most importantly, any changes made by the user should at this
* point be committed (usually to the
* {@link android.content.ContentProvider} holding the data).
* </ul>
...
*/
public class Activity extends ContextThemeWrapper
implements LayoutInflater.Factory2,
Window.Callback, KeyEvent.Callback,
OnCreateContextMenuListener, ComponentCallbacks2 {
private static final String TAG = "Activity";
private static final boolean DEBUG_LIFECYCLE = false; /** Standard activity result: operation canceled. */
//常量命名
public static final int RESULT_CANCELED = 0;
/** Standard activity result: operation succeeded. */
public static final int RESULT_OK = -1;
/** Start of user-defined activity results. */
public static final int RESULT_FIRST_USER = 1; static final String FRAGMENTS_TAG = "android:fragments"; private static final String WINDOW_HIERARCHY_TAG = "android:viewHierarchyState";
private static final String SAVED_DIALOG_IDS_KEY = "android:savedDialogIds";
private static final String SAVED_DIALOGS_TAG = "android:savedDialogs";
private static final String SAVED_DIALOG_KEY_PREFIX = "android:dialog_";
private static final String SAVED_DIALOG_ARGS_KEY_PREFIX = "android:dialog_args_"; private static class ManagedDialog {
Dialog mDialog;
Bundle mArgs;
}
private SparseArray<ManagedDialog> mManagedDialogs; // set by the thread after the constructor and before onCreate(Bundle savedInstanceState) is called.
//私有变量命名
private Instrumentation mInstrumentation;
private IBinder mToken;
private int mIdent; static final class NonConfigurationInstances {
Object activity;
HashMap<String, Object> children;
ArrayList<Fragment> fragments;
HashMap<String, LoaderManagerImpl> loaders;
}
/* package */ NonConfigurationInstances mLastNonConfigurationInstances; private Window mWindow; /**
* Change the intent returned by {@link #getIntent}. This holds a
* reference to the given intent; it does not copy it. Often used in
* conjunction with {@link #onNewIntent}.
*
* @param newIntent The new Intent object to return from getIntent
*
* @see #getIntent
* @see #onNewIntent
*自定义javadoc标签
*@author ..
*@date ..
*@modify ..(who,when..)
*/
public void setIntent(Intent newIntent) {
mIntent = newIntent;
}
Android journey 1@关于编码风格和命名规范的更多相关文章
- Java编程风格与命名规范整理
基本命名规范 包命名 包名按照域名的范围从大到小逐步列出,恰好和Internet上的域名命名规则相反. 由一组以“.”连接的标识符构成,通常第一个标识符为符合网络域名的两个或者三个英文小写字母. Pe ...
- 编码风格和PEP8规范
编码风格 错误认知 这很浪费时间 我是个艺术家 所有人都能穿的鞋不会合任何人的脚 我善长制定编码规范 正确认知 促进团队合作 减少bug处理 提高可读性,降低维护成本 有助于代码审查 养成习惯,有助于 ...
- 转载:Java编程风格与命名规范整理
转载自:传送门 不想复制,点进去看喽23333333
- Android 命名规范 (提高代码可以读性) 转
转自:http://blog.csdn.net/vipzjyno1/article/details/23542617 刚接触android的时候,命名都是按照拼音来,所以有的时候想看懂命名的那个控件 ...
- [转] Android 命名规范 (提高代码可以读性)
Android命名规范编码习惯 刚接触android的时候,命名都是按照拼音来,所以有的时候想看懂命名的那个控件什么是什么用的,就要读一遍甚至好几遍才知道,这样的话,在代码的 审查和修改过程中就会浪费 ...
- Android编码风格
整理一下51CTO学院中张凌华老师讲的编码风格课程 一. 项目开发目录命名: Requirement - 需求相关文档 Design - 设计 Planning&Log - 计划,日志,会议 ...
- 第四章 android 命名规范和编码规范
书里面讲的比较常见,单个人也是有不同的观点: 因为android绝大部分使用java开发的,因此java相关规范适用于android: Google Style: 英文地址:http://google ...
- 【朝花夕拾】Android编码风格篇
结合51CTO学院中张凌华老师讲的编码风格课程,对自己平时工作中的形成的一些编码风格做一些总结. 一. 项目开发目录命名: Requirement - 需求相关文档 Design - 设计 Plann ...
- Android 编码风格规范,很赞哦
1. 前言 这份文档参考了 Google Java 编程风格规范和 Google 官方 Android 编码风格规范.该文档仅供参考,只要形成一个统一的风格,见量知其意就可. 1.1 术语说明 在本文 ...
随机推荐
- 跟我一起学习ASP.NET 4.5 MVC4.0(三)(转)
今天我们继续ASP.NET 4.5 MVC 4.0,前两天熟悉了MVC4.0在VS11和win8下的更新,以及MVC中的基础语法和几个关键字的使用.了解了这些就可以对MVC进一步认识,相信很多人都对M ...
- 【转】Ajax 基础学习
今天简单的学习了 Ajax 的基础知识,总结在这里.部分代码不是原创,特此说明. [Ajax 简介] AJAX = Asynchronous JavaScript and XML(异步的 JavaSc ...
- log4Net 简单配置实用
<configSections> <section name="log4net" type="log4net.Config.Log4NetConfigu ...
- C语言中char* 和 char []区别
想要把丢掉的东西捡起来,还是很辛苦啊,今天我就发现,我连char* 和 char []的区别都不知道. 很多人觉得这两个定义效果一样,其实差别很大.以下是个人的一些看法,有不正确的地方望指正. 本质上 ...
- 对象this、currentTarget和target
在事件处理程序内部,对象this始终等于currentTarget的值,而target则只包含事件的实际目标.如果直接将事件处理程序指定给了目标元素,则this.currentTarget和targe ...
- hdu 2066 一个人的旅行 Dijkstra
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2066 题意分析:以草儿家为原点,给出城市间相互抵达的时间,给出草儿想去的城市,求最短时间.典型的单源最 ...
- Windows下安装GnuRadio最简单的方法(没有之一)
作者在Windows XP SP3 32位下亲测通过,理论上Win7也没问题. 1. 如果系统中安装有Python,请先把Python卸载. 2. 下载安装Python(x,y) 2.7.5.0, 下 ...
- bzoj2395[Balkan 2011]Timeismoney最小乘积生成树
所谓最小乘积生成树,即对于一个无向连通图的每一条边均有两个权值xi,yi,在图中找一颗生成树,使得Σxi*Σyi取最小值. 直接处理问题较为棘手,但每条边的权值可以描述为一个二元组(xi,yi),这也 ...
- 基类和派生类--this
基类指针在程序运行的时候的确指向的是一个派生类的对象,但指针的类型仍然是基类指针.C++是一种强类型语言,因此不能用基类指针类型的指针直接调用派生类:而且,同一个类可能有多种不同的派生类,因此不知道实 ...
- VC和VS系列(2005)编译器对双精度浮点溢出的处理
作者:风影残烛 在还原代码的过程中.目前程序是采用VS2005(以上版本)写的. 我使用的是vc6.0,结果.在运算的时候.发现编译器对 // FpuTlxTest.cpp : 定义控制台应用程序的入 ...