新增章节 1_4

+YUCHENG HU+


git-svn-id: https://svn.code.sf.net/p/hawebs/svn@509 a2543c7e-f6e9-4f8a-8bff-1ffc34733512
This commit is contained in:
YuCheng Hu
2010-07-15 04:31:02 +00:00
parent 8afc8b69d0
commit cfd8fa2acc
3 changed files with 105 additions and 0 deletions
@@ -63,5 +63,7 @@
<topicref href="tasks/chapter1/chapter1_1.dita"/>
<topicref href="tasks/chapter1/chapter1_2.dita"/>
<topicref href="tasks/chapter1/chapter1_3.dita"/>
<topicref href="tasks/chapter1/chapter1_4.dita"/>
<topicref href="tasks/chapter1/chapter1_5.dita"/>
</topicref>
</map>
@@ -0,0 +1,52 @@
<?xml version='1.0' encoding='UTF-8'?>
<!-- This document was created with Syntext Serna Free. --><!DOCTYPE concept PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd" []>
<!--
**
* Copyright (C) 2006-2010 YUCHENG HU
*
* +++++++++++++++++++++++++++++++++++++++++++++++++
* HA WEBSYSTEMS
* http://www.hawebs.net
* http://www.tcivis.com
*
* Contact
* huyuchengus@gmail.com / yuchenghu@hawebs.net
*
* +++++++++++++++++++++++++++++++++++++++++++++++++
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
* GNU GENERAL PUBLIC LICENSE
* APACHE LICENSE, VERSION 2.0
*
* +++++++++++++++++++++++++++++++++++++++++++++++++
-->
<concept id="chapter1_4" xml:lang="zh">
<title>可读性</title>
<prolog>
<metadata>
<keywords>
<indexterm>Java</indexterm>
<indexterm>编码规范</indexterm>
</keywords>
</metadata>
</prolog>
<conbody>
<p><ol>
<li>避免使用不易理解的数字,用有意义的标识来替代。</li>
<li>不要使用难懂的技巧性很高的语句。</li>
<li>源程序中关系较为紧密的代码应尽可能相邻。</li>
</ol></p>
</conbody>
</concept>
@@ -0,0 +1,51 @@
<?xml version='1.0' encoding='UTF-8'?>
<!-- This document was created with Syntext Serna Free. --><!DOCTYPE concept PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd" []>
<!--
**
* Copyright (C) 2006-2010 YUCHENG HU
*
* +++++++++++++++++++++++++++++++++++++++++++++++++
* HA WEBSYSTEMS
* http://www.hawebs.net
* http://www.tcivis.com
*
* Contact
* huyuchengus@gmail.com / yuchenghu@hawebs.net
*
* +++++++++++++++++++++++++++++++++++++++++++++++++
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
* GNU GENERAL PUBLIC LICENSE
* APACHE LICENSE, VERSION 2.0
*
* +++++++++++++++++++++++++++++++++++++++++++++++++
-->
<concept id="chapter1_5" xml:lang="zh">
<title>性能</title>
<prolog>
<metadata>
<keywords>
<indexterm>Java</indexterm>
<indexterm>编码规范</indexterm>
</keywords>
</metadata>
</prolog>
<conbody>
<p>在写代码的时候,从头至尾都应该考虑性能问题。这不是说时间都应该浪费在优化代码上,而是我们时刻应该提醒自己要注意代码的效率。比如:如果没有时间来实现一个高效的算法,那么我们应该在文档中记录下来,以便在以后有空的时候再来实现她。 不是所有的人都同意在写代码的时候应该优化性能这个观点的,他们认为性能优化的问题应该在项目的后期再去考虑,也就是在程序的轮廓已经实现了以后。 </p>
<p>不要在循环中构造和释放对象。</p>
<p>使用 StringBuffer 对象。在处理 String 的时候要尽量使用 StringBuffer 类,StringBuffer 类是构成 String 类的基础。String 类将 StringBuffer 类封装了起来,(以花费更多时间为代价)为开发人员提供了一个安全的接口。当我们在构造字符串的时候,我们应该用 StringBuffer 来实现大部分的工作,当工作完成后将 StringBuffer 对象再转换为需要的 String 对象。比如:如果有一个字符串必须不断地在其后添加许多字符来完成构造,那么我们应该使用 StringBuffer 对象和她的 append() 方法。如果我们用 String 对象代替 StringBuffer 对象的话,会花费许多不必要的创建和释放对象的 CPU 时间。 </p>
<p>避免不必要的使用关键字 synchronized,应该在必要的时候再使用她,这是一个避免死锁的好方法。</p>
</conbody>
</concept>