顯示具有 轉貼 標籤的文章。 顯示所有文章
顯示具有 轉貼 標籤的文章。 顯示所有文章

2011年6月26日 星期日

How Mobile Phones Can Transform Healthcare


推薦者:
楊適旭  院長
台電聯合診所

看到周圍的所有人的生活進入到雲端時代,醫療產業更是隨著無線通訊科技的進步不斷進化中我們現在已經在台大醫院與台北榮總看到病房的護士推著一台台帶著無線通訊科技的護理車來進行護理照護工作,而照護工作得以和醫院的HIS系統連線後可以幫助大幅減少錯誤發生的機率。
更加精采的當然還是雲端運算,最近幫很多診所同事配置了iPhone 4 32G,目的是讓大家更熟悉智慧型手機如何改變你我的生活。
但為了讓我們明白妳的那一隻智慧手機未來和妳的健康有甚麼關聯,能幫妳做甚麼大家不妨看看院長推薦的這篇文章。
How Mobile Phones Can Transform Healthcare
9:56 AM Tuesday March 8, 2011
by David Aylward  | 
Comments ( 9)
Editor's note: This post is part of a three-week series examining innovation in health care, published in partnership with the Advanced Leadership Initiative at Harvard University.
The mobile phone is a strong contender as a key transforming agent in the future of health and healthcare. There are now more than 5.3 billion cell phone users around the globe, and 90 percent of the world's population is covered by a commercial wireless signal. We now have a pathway to reach the unreached, and to deliver health services where people are, not merely in health facilities.

In a world with severe healthcare resource constraints, mobile digital technology can be a major "
force multiplier." It can empower both patients and practitioners by providing them with the information they need to make informed decisions about health issues from healthy living habits, to health care provision, and monitoring of diseases. The rapid expansion of wireless networks represents a particularly exciting opportunity to reach those who are currently isolated by distance and lack of communication, using "mHealth" (mobile health) programs.
In this respect, health care is no different from other economic sectors that have gained enormous efficiencies and improved outcomes through the use of modern information and communications technologies (ICT). With its ability to reach much further into developing countries than any other technology, wireless is today powering the collection of health data, supporting diagnosis and treatment, and advancing education and research in even the most remote and resource-poor environments — with the potential to do far more.
There are a number of challenges to taking full advantage of this opportunity. One is figuring out the proper mix of public and private involvement.
We don't understand the business models that will support real public private partnerships in the deployment and sustainability of mHealth systems. I just spent a week in Barcelona at the annual gathering of the wireless industry. We want to harness the same drive for health that has been delivering profitable wireless service in the remotest and poorest parts of the world. The interest level is very high, but so far most private sector support for mHealth is still limited to charity. It is not yet clear how the industry will make money on it.
mHealth business models have emerged where there is one buyer for a solution to a specific problem. For example, Sproxil has found pharmaceutical buyers for its anti-drug counterfeiting service. Sproxil allows individuals to easily determine if a drug is legitimate with a single SMS message of a scratched-off number. Ensuring brand protection for the pharmaceutical company creates a business.
However, the real power of mHealth is in supporting integrated health systems involving multiple public and private parties offering diverse services and products. For these multi-problem, multi-actor systems, we have not yet developed clear value chains, much less business models.
Once we start to do that, and we create larger scale implementations, we will be able to see how far private market incentives will go in addressing the enormous needs, especially in the developing world.
We think that offering an array of health services via wireless will generally drive up sales and usage. We think it will drive the sale of more sophisticated handsets and networks. But that "array" has yet to be offered, much less measured.
More narrowly, will offering smart phones to front line health workers pay for itself in increased sales to others? Will hosting an electronic health record and package of health applications for maternal and newborn care justify itself in higher female subscriptions? Will lower data rates for health workers be justified by sparking higher overall demand?
These are all colorable propositions. They need to be tested at scale.
From its earliest days, the US wireless industry offered emergency 9-1-1 calls for free. Years ago I bought cell service for my daughters so they would be safer. I don't think they ever called 9-1-1, but the offer contributed substantially to the growth of the US wireless industry. That industry has a similar opportunity with mHealth, especially in emerging markets.
The industry cannot deliver mHealth on its own, and the private market is not going to solve all health issues by any means. But understanding how much the industry can and will do in its own interests is an important part of the puzzle.
David Aylward is the first Executive Director of the mHealth Alliance — a partnership recently formed by the UN Foundation, The Vodafone Foundation, and Rockefeller Foundation.

2011年1月16日 星期日

音樂毒品大收集

音樂毒品大收集

http://freakshare.com/files/skly53xd/french_roast.mp3.html
http://freakshare.com/files/fc62yrfm/a-bomb.mp3.html
http://freakshare.com/files/teqra17x/5htp.mp3.html
http://freakshare.com/files/ldxq7dnt/heroin.mp3.html
http://freakshare.com/files/zm1gerd1/hash.mp3.html
http://freakshare.com/files/wy5lp12i/hangover_cure.mp3.html
http://freakshare.com/files/prz3dvk2/hand_of_god.mp3.html
http://freakshare.com/files/aaw5tnhf/gray-b-gone.mp3.html
http://freakshare.com/files/wcdkt4np/gamma.mp3.html
http://freakshare.com/files/yut7j62x/first_love.mp3.html
http://freakshare.com/files/mfhzleth/excite.mp3.html
http://freakshare.com/files/m85aka3g/ecstasy.mp3.html
http://freakshare.com/files/td3ro4rl/downer.mp3.html
http://freakshare.com/files/bz07wy23/dmt.mp3.html
http://freakshare.com/files/8ge95wli/divinorum.mp3.html
http://freakshare.com/files/1c7wwm8g/dexies.mp3.html
http://freakshare.com/files/prq0t95j/demerol.mp3.html
http://freakshare.com/files/o79onie2/delta.mp3.html
http://freakshare.com/files/vwzot95p/crystal_meth.mp3.html
http://freakshare.com/files/8x6m01bb/content.mp3.html
http://freakshare.com/files/jt5dt2o0/cliff_hanger.mp3.html
http://freakshare.com/files/ox3b93yu/cocaine.mp3.html
http://freakshare.com/files/e2mvpang/genesis.mp3.html
http://freakshare.com/files/ehad8pk3/extend.mp3.html
http://freakshare.com/files/gnnk6mrn/energizer.mp3.html
http://freakshare.com/files/j5vsro47/dxm.mp3.html
http://freakshare.com/files/2g5lcjht/chakra.mp3.html
http://freakshare.com/files/nu022xhu/opium.mp3.html
http://freakshare.com/files/6v44ibst/nitrous.mp3.html
http://freakshare.com/files/2cqitlcy/nicotine.mp3.html
http://freakshare.com/files/mcfiyv9y/multipleo.mp3.html
http://freakshare.com/files/k38q6nry/morphine.mp3.html
http://freakshare.com/files/n8oousnl/masochist.mp3.html
http://freakshare.com/files/e022mghm/marijuana.mp3.html
http://freakshare.com/files/z47wa5b9/lsd.mp3.html
http://freakshare.com/files/l0h7dpmu/lucid_dream.mp3.html
http://freakshare.com/files/4pimiyiz/juiceit.mp3.html
http://freakshare.com/files/14tmwvwv/inspire.mp3.html
http://freakshare.com/files/ohc62era/insomniac.mp3.html
http://freakshare.com/files/fqxpzplb/inhalant.mp3.html
http://freakshare.com/files/56offq2x/calm_me.mp3.html
http://freakshare.com/files/llx4ml7g/bufo_toad.mp3.html
http://freakshare.com/files/4596br25/brain-.mp3.html
http://freakshare.com/files/ze61fph8/black_sunshine.mp3.html
http://freakshare.com/files/ypwh8tcz/beta.mp3.html
http://freakshare.com/files/npxjc15p/astral_projection.mp3.html
http://freakshare.com/files/70k714ib/anti-migraine.mp3.html
http://freakshare.com/files/q80ri2yq/anesthesia.mp3.html
http://freakshare.com/files/t6c80mjc/antisad.mp3.html
http://freakshare.com/files/rfodhaj1/peyote.mp3.html
http://freakshare.com/files/hgwps185/orgasm.mp3.html
http://freakshare.com/files/txp7zt8c/out_of_body.mp3.html
http://freakshare.com/files/941lxm6w/quickhappy.mp3.html
http://freakshare.com/files/0amte2o0/you-choose.mp3.html
http://freakshare.com/files/dg1fwj3o/oxy.mp3.html
http://freakshare.com/files/2y0lorx0/theta.mp3.html
http://freakshare.com/files/plvhyqtx/speed.mp3.html
http://freakshare.com/files/attmorgd/sleeping_angel.mp3.html
http://freakshare.com/files/842wuxvd/serene.mp3.html
http://freakshare.com/files/qmwf1dpw/quit.mp3.html
http://freakshare.com/files/v8c4lmsz/yaba.mp3.html
http://freakshare.com/files/adsy3c1f/white_crosses.mp3.html
http://freakshare.com/files/mv6ry9a8/victory.mp3.html
http://freakshare.com/files/admlx11m/tranquil.mp3.html
http://freakshare.com/files/e8yg4i7e/trip.mp3.html
http://freakshare.com/files/zgcue9lf/aftermath.mp3.html
http://freakshare.com/files/s5yjspcj/alpha.mp3.html
http://freakshare.com/files/fok429s8/afterglow.mp3.html
http://freakshare.com/files/k2rqy5so/alcohol.mp3.html
http://freakshare.com/files/89tz5skn/vico.mp3.html
http://freakshare.com/files/06dmy1jo/adrenochrome.mp3.html
http://freakshare.com/files/3ts2y1z1/acid.mp3.html
http://freakshare.com/files/s4h8levt/reset.mp3.html
http://freakshare.com/files/zksz4tk2/absinthe.mp3.html
http://freakshare.com/files/ezoz4sj8/Ketamine.mp3.html
http://freakshare.com/files/f5624vj7/0rave.mp3.html
http://freakshare.com/files/xod08z6r/prozium.mp3.html

How To Set Up Apache2 With mod_fcgid And PHP5 On Ubuntu 8.10

How To Set Up Apache2 With mod_fcgid And PHP5 On Ubuntu 8.10

Version 1.0 
Author: Falko Timme  
Last edited 01/29/2009
This tutorial describes how you can install Apache2 with mod_fcgid and PHP5 on Ubuntu 8.10. mod_fcgid is a compatible alternative to the older mod_fastcgi. It lets you execute PHP scripts with the permissions of their owners instead of the Apache user.
I do not issue any guarantee that this will work for you!

1 Preliminary Note

I'm using an Ubuntu 8.10 server in this tutorial with the hostname server1.example.com and the IP address192.168.0.100.
I will create two Apache vhosts in this tutorial, www.example1.com and www.example2.com, to demonstrate the usage of mod_fcgid.
Make sure you're logged in as root:
sudo su
/bin/sh is a symlink to /bin/dash, however we need /bin/bash, not /bin/dash. Therefore we do this:
ln -sf /bin/bash /bin/sh
In addition to that, we must disable AppArmor:
/etc/init.d/apparmor stop
update-rc.d -f apparmor remove
apt-get remove apparmor apparmor-utils

2 Installing Apache2/mod_fcgi/PHP5

In order to install Apache2, mod_fcgid, and PHP5, run
apt-get install apache2 apache2-suexec libapache2-mod-fcgid php5-cgi
If Apache2 was already installed with PHP5 as an Apache module, disable the PHP5 module now:
a2dismod php5
Then enable the following modules...
a2enmod rewrite
a2enmod suexec
a2enmod include
a2enmod fcgid
... and open /etc/php5/cgi/php.ini:
vi /etc/php5/cgi/php.ini
Add the line cgi.fix_pathinfo = 1 right at the end of the file:
[...]
cgi.fix_pathinfo = 1
Then reload Apache:
/etc/init.d/apache2 force-reload

3 Creating Vhosts For www.example1.com And www.example2.com

I will now create two vhosts, www.example1.com (with the document root /var/www/web1/web) and www.example2.com (with the document root /var/www/web2/web).www.example1.com will be owned by the user and group web1, and www.example2.com by the user and group web2.
First we create the users and groups:
groupadd web1
groupadd web2
useradd -s /bin/false -d /var/www/web1 -m -g web1 web1
useradd -s /bin/false -d /var/www/web2 -m -g web2 web2
Then we create the document roots and make them owned by the users/groups web1 resp. web2:
mkdir -p /var/www/web1/web
chown web1:web1 /var/www/web1/web
mkdir -p /var/www/web2/web
chown web2:web2 /var/www/web2/web
We will run PHP using suExec; suExec's document root is /var/www, as the following command shows:
/usr/lib/apache2/suexec -V
root@server1:~# /usr/lib/apache2/suexec -V
 -D AP_DOC_ROOT="/var/www"
 -D AP_GID_MIN=100
 -D AP_HTTPD_USER="www-data"
 -D AP_LOG_EXEC="/var/log/apache2/suexec.log"
 -D AP_SAFE_PATH="/usr/local/bin:/usr/bin:/bin"
 -D AP_UID_MIN=100
 -D AP_USERDIR_SUFFIX="public_html"
root@server1:~#
mkdir -p /var/www/php-fcgi-scripts/web1
mkdir -p /var/www/php-fcgi-scripts/web2
vi /var/www/php-fcgi-scripts/web1/php-fcgi-starter
#!/bin/sh
PHPRC=/etc/php5/cgi/
export PHPRC
export PHP_FCGI_MAX_REQUESTS=5000
export PHP_FCGI_CHILDREN=8
exec /usr/lib/cgi-bin/php
vi /var/www/php-fcgi-scripts/web2/php-fcgi-starter
#!/bin/sh
PHPRC=/etc/php5/cgi/
export PHPRC
export PHP_FCGI_MAX_REQUESTS=5000
export PHP_FCGI_CHILDREN=8
exec /usr/lib/cgi-bin/php
The PHPRC line contains the directory where the php.ini file is located (i.e., /etc/php5/cgi/ translates to /etc/php5/cgi/php.ini). PHP_FCGI_MAX_REQUESTS is the maximum number of requests before an fcgid process is stopped and a new one is launched. PHP_FCGI_CHILDREN defines the number of PHP children that will be launched.
The php-fcgi-starter scripts must be executable, and they (and the directories they are in) must be owned by the web site's user and group:
chmod 755 /var/www/php-fcgi-scripts/web1/php-fcgi-starter
chmod 755 /var/www/php-fcgi-scripts/web2/php-fcgi-starter
chown -R web1:web1 /var/www/php-fcgi-scripts/web1
chown -R web2:web2 /var/www/php-fcgi-scripts/web2
Now we create the Apache vhosts for www.example1.com and www.example2.com:
vi /etc/apache2/sites-available/web1

  ServerName www.example1.com
  ServerAlias example1.com
  ServerAdmin webmaster@example1.com
  DocumentRoot /var/www/web1/web/

  
    SuexecUserGroup web1 web1
    PHP_Fix_Pathinfo_Enable 1
    
      Options +ExecCGI
      AllowOverride All
      AddHandler fcgid-script .php
      FCGIWrapper /var/www/php-fcgi-scripts/web1/php-fcgi-starter .php
      Order allow,deny
      Allow from all
    
  

  # ErrorLog /var/log/apache2/error.log
  # CustomLog /var/log/apache2/access.log combined
  ServerSignature Off

a2ensite web1
vi /etc/apache2/sites-available/web2

  ServerName www.example2.com
  ServerAlias example2.com
  ServerAdmin webmaster@example2.com
  DocumentRoot /var/www/web2/web/

  
    SuexecUserGroup web2 web2
    PHP_Fix_Pathinfo_Enable 1
    
      Options +ExecCGI
      AllowOverride All
      AddHandler fcgid-script .php
      FCGIWrapper /var/www/php-fcgi-scripts/web2/php-fcgi-starter .php
      Order allow,deny
      Allow from all
    
  

  # ErrorLog /var/log/apache2/error.log
  # CustomLog /var/log/apache2/access.log combined
  ServerSignature Off

a2ensite web2
Make sure you fill in the right paths (and the correct user and group in the SuexecUserGroup line).
Reload Apache afterwards:
/etc/init.d/apache2 reload

2010年5月2日 星期日

Java、Applet 与 javascript 间的通信


2008-12-19 20:49
  本文着重阐述了网页开发中,通过灵活使用从JavaScript语言中访问Java的方法、从JavaScript中访问JavaScript小程序的方法与变量,以及在Java Applet小程序中使用JavaScript等技术,实现这几种网页开发语言的互相补充,以开发更完美的Web应用程序。 

JavaScript是用于HTML环境的开发语言,提供了能够响应Web页面事件的脚本,可以完全访问浏览器窗口的各个方面,善于合并HTML、Java Applet小程序、插入件、服务器方程序和其他Web组件,形成完全集成的Web应用程序。而Java是功能强大的著名开发语言,能够支持Web应用程序的开发,用于开发高级Web对象,并提供实现嵌入Web页面的可执行内容,具有更强的编程功能,可以作为JavaScript功能的良好补充,只不过这些功能被限制在有限的浏览器窗口区中。 
Java与JavaScript可以互相补充,以开发功能更完美的Web应用程序。本文归纳了笔者编程中曾使用过的,涉及到有关JavaScript与Java、Java Applet小程序之间互访的问题的一些方法,仅供参考。

一、从JavaScript中访问Java方法

在HTML脚本中可以用JavaScript直接调用Java中的方法,只需要在调用语句前用“java.lang.”加以表示即可。具体语句用法如下例所示: 
java.Lang.System.Out.println(“Hello!”) 
但此种方法只适用于Netscape Navigator,一般不提倡在Web应用程序中使用。 

二、从JavaScript中访问Java Applet小程序中的方法和变量 

通过JavaScript提供的Applet对象,JavaScript代码可以访问Java的变量和方法,具体步骤和用法示例如下。需要注意的是,JavaScript提供的applet对象具有name属性,而没有方法和事件处理器。 
步骤: 

1) 将要访问的Java Applet小程序的方法和变量声明为Public,且必须在Public类中声明; 
2) Java Applet小程序要先装入才能访问,尽管applet对象没有定义onLoad事件,但可以在HTML文档的〈body〉标志中,指定使用Window对象的onLoad事件处理器; 
3) Java Applet小程序可以用JavaScript的applet对象来访问。 

示例: 
“mytest.htm” 
 
 
 
 
 
//通过调用accessApplet()装入小程序 
  
 
 
“Testtext.java” 
import java.applet.*; 
…… 
public class Testtext extends Applet 
{ …… 
public void setText(String s) //setText()必须声明为“public” 

text=s; 
repaint(); 




三、在Java Applet小程序中使用JavaScript 

Live Connect提供了Java与JavaScript的接口,可以允许在Java Applet小程序中使用JavaScript。具体步骤如下: 
1) 在HTML脚本中使用〈APPLET〉标志的MAYSCRIPT属性,以允许Java Applet小程序访问脚本; 
2) 将netscape. JavaScript包导入Java Applet小程序; 
3) 在Java Applet小程序中用JSObject类的getWindow( )方法创建JavaScript窗口的句柄; 
4) 在Java Applet小程序中用JSObject类的getMember( )方法访问JavaScript对象; 
5) 在Java Applet小程序中用JSObject类的eval( )方法调用JavaScript方法。 

示例: 
“ReadForm. Java” 
import netscape.javascript.JSObject; 
import netscape.javascript.JSException; //可允许在小程序中处理异常事件 
…… 
win=JSObject.getWindow(this); // 获取JavaScript窗口句柄,引用当前文档窗口 
doc=(JSObject)win.getMember("document"); // 访问JavaScript对象 
form=(JSObject)doc.getMember("textForm"); 
textField=(JSObject)form.getMember("textField"); 
text=(String) textField.getMember("value"); //获取文本区的值 
…… 
win.eval("alert(\"This alert comes from Java!\")"); 
// 调用JavaScript的alert()方法 
…… 
“User.htm” 
…… 
 
 
Enter text and then click display text: 

 
 
 
//必须使用MAYSCRIPT属性标志 
 


【来源:http://www.3800hk.com/Article/cxsj/java/asjava/2005-08-06/Article_21812.html】

Java程序员需坚守的十大基本准则

http://twyok.blog.163.com/blog/static/8122930320103234840160/?latestBlog


一、为代码加注释。虽然每个人都知道这点,但有时却不自觉忘了履行,今天你“忘了”加注释了吗?虽然注释对程序的功能没什么“贡献”,但过一段时间,比如说两星期之后或者更长,回过头来看看自己的代码,说不定已经记不住它是干什么的了。如果这些代码是你个人的,那还算是走运了,不幸的是,当然了,大多数时候都是别人的不幸,很多时候大家都是在为公司写代码,写代码的人也许早已经离开了公司,但别忘了一句古话,有来有往嘛,为他人,也为我们自己,请为你的代码加上注释。
二、不要让事情复杂化。程序员有时候总是对简单问题想出复杂的解决方案,比如说,在只有五个用户的程序中引入EJB、对程序实现了并不需要的框架(framework),之类的还有属性文件、面向对象解决方案、多线程等等。为什么要这样做呢?也许我们并不知道是否这样会更好,但这样做也许可以学到一些新东西,或者让自己更感兴趣一些。如果是不知道为什么这样做,建议多请教经验丰富的程序员,如果是为了个人的目的,麻烦让自己更专业一点。
三、始终牢记——“少即是好(Less is more)并不总是对的”。代码效率虽然很重要,但在许多解决方案中,编写更少的代码并不能改善这些代码的效率,请看下面这个简单的例子:
if(newStatusCode.equals("SD") && (sellOffDate == null ||todayDate.compareTo(sellOffDate)<0 || (lastUsedDate != null &&todayDate.compareTo(lastUsedDate)>0)) ||(newStatusCode.equals("OBS") && (OBSDate == null ||todayDate.compareTo(OBSDate)<0))){newStatusCode = "NYP"; }
能看明白if条件语句是干什么的吗?能想出来是谁写的这段代码吗?如果把它分成两段独立的if语句,是不是更容易理解呢,下面是修改后的代码:
if(newStatusCode.equals("SD") && (sellOffDate == null ||todayDate.compareTo(sellOffDate)<0 || (lastUsedDate != null &&todayDate.compareTo(lastUsedDate)>0))){newStatusCode = "NYP"; }elseif(newStatusCode.equals("OBS") && (OBSDate == null ||todayDate.compareTo(OBSDate)<0)){newStatusCode = "NYP"; }
是不是读起来容易多了呢,在此只是多加了一个if和两个花括号,但代码的可读性与可理解性就一下子提高了一大截。
四、请不要硬编码。开发者经常有意“忘记”或忽略掉这点,因为有些时候开发日程逼得实在太紧。其实,多写一行定义静态变量的代码能花多少时间呢?
public class A {public static final String S_CONSTANT_ABC = "ABC"; public boolean methodA(String sParam1){if (A.S_CONSTANT_ABC.equalsIgnoreCase(sParam1)){return true; }return false; }}
现在,每次需要将“ABC”与其他变量进行比较时,不必记住实际代码,直接引用A.S_CONSTANT_ABC就行了,而且在今后需要进行修改时,也可在一处修改,不会翻遍整个源代码逐个修改了。
五、不要“创造”自己的框架(framework)。确切来说,有数以千计的各种框架存在,而且大多数是开源的,这些框架都是优秀的解决方案,可用于日常程序开发中,我们只需使用这些框架的最新版本就行了,至少表面上要跟上形势吧。被大家广为接受的最为明显的一个例子就是Struts了,这个开源web框架非常适合用在基于web的应用程序中。是不是想开发出自己的Struts呢,还是省点力气吧,回头看看第二条——不要让事情复杂化。另外,如果正在开发的程序只有3个窗口,就不要使用Struts了,对这种程序来说,不需要那么多的“控制”。
六、不要使用println及字符串连接。通常为了调试方便,开发者喜欢在可能的所有地方都加上System.out.println,也许还会提醒自己回过头来再来删除,但有些时候,经常会忘了删除或者不愿意删除它们。既然使用System.out.println是为了测试,那么测试完之后,为什么还要留着它们呢,因为在删除时,很可能会删除掉真正有用的代码,所以不能低估System.out.println危害啊,请看下面的代码:
public class BadCode {public static void calculationWithPrint(){double someValue = 0D; for (int i = 0; i <10000; i++) {System.out.println(someValue = someValue + i); }}public static void calculationWithOutPrint(){double someValue = 0D; for (int i = 0; i < 10000; i++) {someValue = someValue + i; }}public static void main(String [] n) {BadCode.calculationWithPrint(); BadCode.calculationWithOutPrint(); }}
从测试中可以发现,方法calculationWithOutPrint()执行用了0.001204秒,作为对比,方法calculationWithPrint()执行可是用了10.52秒。
要避免浪费CPU时间,最好的方法是引入像如下的包装方法:
public class BadCode {public static final int DEBUG_MODE = 1; public static final int PRODUCTION_MODE = 2; public static void calculationWithPrint(int logMode){double someValue = 0D; for (int i = 0; i < 10000; i++) {someValue = someValue + i; myPrintMethod(logMode, someValue); }}public static void myPrintMethod(int logMode, double value) {if (logMode > BadCode.DEBUG_MODE) { return; }System.out.println(value); }public static void main(String [] n) {BadCode.calculationWithPrint(BadCode.PRODUCTION_MODE); }}
另外,字符串连接也是浪费CPU时间的一个大头,请看下面的示例代码:
public static void concatenateStrings(String startingString) {for (int i = 0; i < 20; i++) {startingString = startingString + startingString; }}public static void concatenateStringsUsingStringBuffer(String startingString) {StringBuffer sb = new StringBuffer(); sb.append(startingString); for (int i = 0; i < 20; i++) {sb.append(sb.toString()); }}
在测试中可发现,使用StringBuffer的方法只用了0.01秒执行完毕,而使用连接的方法则用了0.08秒,选择显而易见了。
七、多关注GUI(用户界面)。再三强调,GUI对商业客户来说,与程序的功能及效率同等重要,GUI是一个成功程序的最基本部分,而很多IT经理往往都没注意到GUI的重要性。在现实生活中,许多公司可能为了节省开支,没有雇用那些有着设计“用户友好”界面丰富经验的网页设计者,此时Java开发者只能依赖他们自身的HTML基本功及在此领域有限的知识,结果,很多开发出来的程序都是“计算机友好”甚于“用户友好”。很少有开发者同时精通软件开发及GUI设计,如果你在公司“不幸”被分配负责程序界面,就应该遵守下面三条原则:
1、 不要再发明一次轮子,即不做无用功。现有的程序可能会有类似的界面需求。
2、 先创建一个原型。这是非常重要一步,用户一般想看到他们将使用的东西,而且可以先利用这个原型征求用户的意见,再慢慢修改成用户想要的样子。
3、 学会换位思考。换句话来说,就是从用户的角度来审查程序的需求。举例来讲,一个汇总的窗口可以跨页或者不跨页,作为一个软件开发者,可能会倾向于不跨页,因为这样简单一些。但是,从用户的角度来看,可能不希望看到上百行数据都挤在同一页上。
八、文档需求不放松。每个商业需求都必须记录在案,这可能听上去像童话,似乎在现实生活中很难实现。而我们要做的是,不管开发时间多紧迫,不管最终期限多临近,对每个商业需求都必须记录在案。
九、单元测试、单元测试、单元测试。关于什么是单元测试的最好方法,在此不便细说,只是强调,单元测试一定要完成,这也是编程中最基本的原则。当然了,如果有人帮你做单元测试自然是最好,如果没有,就自己来做吧,当创建一个单元测试计划时,请遵守以下三条最基本的原则:
1、 先于编写类代码之前编写单元测试。
2、 记录单元测试中的代码注释。
3、 测试所有执行关键功能的公有方法,这里不是指set和get方法,除非它们是以自己独特方式执行set和get方法。
十、质量,而不是数量。有些时候因为产品问题、期限紧迫、或一些预料之外的事情,导致常常不能按时下班,但一般而言,公司不会因为雇员经常加班而对之表扬和奖励,公司只看重高质量的工作。如果遵守了前九条原则,你会发现自己写出的代码bug少。
推到 Twitter!
推到 Plurk!
推到 Facebook!