Morning@Weblog

6/27/2005

爱心拯救程序员王俊

Filed under: — site admin @ 10:09 am

祝福后山,早日康复。这里是本次活动的官方网站。

6/24/2005

Sitemesh Tutorial(2)

Filed under: — site admin @ 2:18 pm

sitemesh中decorate pattern的匹配规则

查看sitemesh的PathMapper代码可以知,在解析decorates.xml文件时,sitemesh对url pattern的匹配分为三类:精确匹配,模糊匹配,缺省匹配。

String result = findExactKey(path, mappings);
if (result == null) result = findComplexKey(path, mappings);
if (result == null) result = findDefaultKey(mappings);

所谓精确匹配是指严格相等,比如:url为/a/b/c.jsp,则与内容为/a/b/c.jsp的pattern匹配;而模糊匹配则是带有“*”、“?”之类的匹配串,比如:url为/a/b/c.jsp,则与内容为/a/b/*的pattern匹配;至于缺省匹配则是精确对应于“/”、“*”、“/*”的匹配项。

其中,精确匹配优先进行,模糊匹配次之,最后才是缺省匹配,如果前二者找到匹配项,则不进行缺省匹配。因此,对于内容为/a/b/c.jsp和/a/b/*的pattern同时出现时,/a/b/c.jsp首先匹配前者。

对于模糊匹配,sitemesh采用最长匹配原则,以下代码摘自PathMapper:

Iterator i = mappings.keySet().iterator();
String result = null, key = null;
while (i.hasNext()) {
 key = (String) i.next();
 if (key.length() > 1 && (key.indexOf(’?') != -1 || key.indexOf(’*') != -1) && match(key, path, false)) {
  if (result == null || key.length() > result.length()) {
   // longest key wins
   result = key;
  }
 }
}

因此,对于内容为/a/*、/a/b/*、/a/b/c.jsp的pattern,url为/a/b/c.jsp将匹配最后一项。

而对于decorates.xml中的excludes定义,由于是在最先判断的,因此具有最高优先级。只要满足excludes中定义的pattern,即可免去后续判断。

此外,由于sitemesh使用HashMap保存decorator pattern,因此如果存在多个decorator中定义了相同的pattern,则最后只有唯一的pattern存在

基于上述规则,我们可以在web.xml中只简单的声明sitemesh filter的url-pattern为“/*”,然后在decorate.xml中根据实际需要定义出复杂的pattern。

6/19/2005

JDK各版本发布时间及代号

Filed under: — site admin @ 5:42 pm

基本来自gigix的blog,并做了修改。

版本号 名称 中文名 发布日期
JDK 1.1.4 Sparkler 宝石 1997-09-12
JDK 1.1.5 Pumpkin 南瓜 1997-12-13
JDK 1.1.6 Abigail 阿比盖尔–女子名 1998-04-24
JDK 1.1.7 Brutus 布鲁图–古罗马政治家和将军 1998-09-28
JDK 1.1.8 Chelsea 切尔西–城市名 1999-04-08
J2SE 1.2 Playground 运动场 1998-12-04
J2SE 1.2.1 none 1999-03-30
J2SE 1.2.2 Cricket 蟋蟀 1999-07-08
J2SE 1.3 Kestrel 美洲红隼 2000-05-08
J2SE 1.3.1 Ladybird 瓢虫 2001-05-17
J2SE 1.4.0 Merlin 灰背隼 2002-02-13
J2SE 1.4.1 grasshopper 蚱蜢 2002-09-16
J2SE 1.4.2 Mantis 螳螂 2003-06-26
J2SE 5.0 (1.5.0) Tiger 老虎 2004-09-30
J2SE 5.1 (1.5.1) Dragonfly 蜻蜓 未知
J2SE 6.0 (1.6.0) Mustang 野马 预计2006年
J2SE 7.0 (1.7.0) Dolphin 海豚 未知

Sun JDK的发展历程

Filed under: — site admin @ 1:13 am

这几天忙于为《程序员》杂志的下一期专题“Java 10周年”撰文。查阅资料之余到是对Java的发展史,产生了浓厚的兴趣。包括早期Java诞生的传奇故事,以及Sun JDK的发展历程,……,一个个线索,一段段记忆的碎片,衔接在一起还真是别有一番意味在其中。

关于Sun JDK,大致可以分作如下几个阶段:
*1996年1月,JDK 1.0,JDK的首个版本。
*1996年12月,JDK 1.1,重写AWT(引入新的事件模型),JavaBean组件规范,inner class,math包
*1998年,JDK 1.2,Swing,Java 2D,Collection Framework
*1998-1999,JDK被从Java Development Kit更名为Java 2 SDK,Java技术被进一步分为J2SE,J2EE,J2ME三个方向
*2000年,J2SE 1.3,引入HotSpot技术
*2002年2月,J2SE 1.4,首个JCP参与的J2SE发布版本,assert,Java Plug-in,Web Start,DOM[level 2],SAX 2.0,JDBC 3.0
*2004年9月30日,J2SE 5.0,泛型,元数据,其他语法特性,线程库,JDBC等
*2006年,J2SE 6.0,(未知)

这里是每个时期的参考资料:
[JDK 1.0/1.1]
JDK 1.0 to JDK 1.1: Making the Transition Listening for Events
JDK 1.0 and Beyond: Making the Transition
Trail: JDK™ 1.1 — And Beyond!

[JDK 1.2]
JDK 1.2 Roadmap: New Features and Functionality
JDK 1.2 Roadmap: All Things New with JDK 1.2

[JDK 1.3]
Java 2 SDK, Standard Edition, version 1.3 Summary of New Features and Enhancements
Improving on Excellence

[JDK 1.4]
Java 2 Platform, Standard Edition, Version 1.4 Overview
Java 2 Platform, Standard Edition (J2SE), Version 1.4.1 Preview
A Roadmap for Java 2 Platform, Standard Edition (J2SE) 1.4.2 and 1.5

[JDK 1.5]
Tiger Roars:an Interview with Sun Microsystems Vice President Graham Hamilton
Tiger and Beyond, the Future of the Java Platform
From Mantis to Tiger
The All-New Java 2 Platform, Standard Edition (J2SE) 5.0 Platform:Programming with the New Language Features in J2SE 5.0

[Misc]
J2SE Naming and Versioning
J2SE 5.0 Name and Version Change
Sun’s Java HotSpot Performance Engine Hits the Spot
Trail Map Your guide to The Java Tutorial
DYNAMIC GENERATION FOR THE WEB: JavaServer Pages 1.0 Technology

如果要研究Java的历史,发现最好的地方是java的官方网站,尤其是Feature Stories About Java Technology
,上面记录了差不多自Java诞生以来,每年所发生的重大事件。

6/17/2005

Sitemesh Tutorial(1)

Filed under: — site admin @ 3:08 pm

为团队做的简单的Sitemesh培训提纲。

Introduction

sitemesh是opensymphony的一个子项目,旨在提高页面可维护性和复用性。它依据经典的Decorator Pattern,利用filter拦截http request/response,再为其加上“装饰”页面,从而达到基于模板结构的多页面复合视图的效果。与“JSP include”的区别在于,我们不需要在每个JSP页面中加入对页面模板布局的表达,被装饰页面所反应的内容正是它自己所关注的内容。

Hello World

1.WEB-INF/web.xml中加入filter定义:

<filter>
 <filter-name>sitemesh</filter-name>
 <filter-class>com.opensymphony.module.sitemesh.filter.PageFilter</filter-class>
</filter>
<filter-mapping>
 <filter-name>sitemesh</filter-name>
 <url-pattern>/*</url-pattern>
</filter-mapping>

2.WEB-INF/web.xml中加入sitemesh的tag lib定义:

<taglib>
 <taglib-uri>sitemesh-decorator</taglib-uri>
 <taglib-location>/WEB-INF/sitemesh-decorator.tld</taglib-location>
</taglib>
<taglib>
 <taglib-uri>sitemesh-page</taglib-uri>
 <taglib-location>/WEB-INF/sitemesh-page.tld</taglib-location>
</taglib>

3.将必需的jar, tld文件拷贝至相应目录:

sitemesh.jar,WEB-INF/lib
sitemesh-decorator.tld ,WEB-INF
sitemesh-page.tld,WEB-INF

4.创建WEB-INF/decorators.xml,配置装饰页面:

<decorators defaultdir="/decorators">
 <decorator name="main” page="main.jsp">
  <pattern>*</pattern>
 </decorator>
</decorators>

5.创建装饰页面:

<%@ page contentType="text/html; charset=GBK"%>
<%@ taglib uri="sitemesh-decorator” prefix="decorator” %>
<html>
 <head>
  <title><decorator:title /></title>
  <decorator:head />
 </head>
 <body>
  Hello World
  <hr />
  <decorator:body />
 </body>
</html>

6.创建被装饰页面:

<%@ page contentType="text/html; charset=GBK"%>
<html>
 <head>
  <title>Hello World</title>
 </head>
 <body>
  <p>Decorated page goes here.</p>
 </body>
</html>

7.部署至tomcat并启动,访问备装饰页面。

BJUG周年庆

Filed under: — site admin @ 12:31 am

多亏nemo提醒,因着BJUG里好几个member都在自己的blog上记了一笔,我想也不能落下啊,所以也免不了落一下俗套了:)

今天看到maillist里最长的thread, 感觉其乐融融。很高兴看到BJUG走完1年历程,哦不,算起来是1年多了,如果按去年4月份的话,我应该是半年后来到BJUG的,当时还叫Java Party。在这里,我看到了老朋友银狐,还有小陶,同时还结识了很多新朋友。记得当初找到李默,是因为看到他在blog上号称要招收敏捷团队,于是带着敬仰之情想向他请教敏捷方法,后来也一直未果:( 不过到是颇有意外之喜,半年多来收获颇丰,眼界也开阔了不少,衷心希望BJUG能够越走越好,也希望自己可以尽一份绵薄之力:D

6/16/2005

成为编程高手的八大奥秘(转)

Filed under: — site admin @ 11:17 am

from http://spaces.msn.com/members/optimizer/feed.rss

扎实的基础 丰富的想像力 最简单的是最好的 不钻牛角尖 对答案的渴求 多与别人交流 良好的编程风格 韧性和毅力
  
1、扎实的基础
  数据结构、离散数学、编译原理,这些是所有计算机科学的基础,如果不掌握它们,很难写出高水平的程序。程序人人都会写,但当你发现写到一定程度很难再提高的时候,就应该想想是不是要回过头来学学这些最基本的理论。不要一开始就去学OOP,即使你再精通OOP,遇到一些基本算法的时候可能也会束手无策。因此多读一些计算机基础理论方面的书籍是非常有必要的。

2、丰富的想像力

  不要拘泥于固定的思维方式,遇到问题的时候要多想几种解决问题的方案,试试别人从没想过的方法。丰富的想像力是建立在丰富的知识的基础上,除计算机以外,多涉猎其他的学科,比如天文、物理、数学等等。开阔的思维对程序员来说很重要。

3、最简单的是最好的

  这也许是所有科学都遵循的一条准则,复杂的质能转换原理在爱因斯坦眼里不过是一个简单得不能再简单的公式:E=mc2。简单的方法更容易被人理解,更容易实现,也更容易维护。遇到问题时要优先考虑最简单的方案,只有简单方案不能满足要求时再考虑复杂的方案。

4、不钻牛角尖

  当你遇到障碍的时候,不妨暂时远离电脑,看看窗外的风景,听听轻音乐,和朋友聊聊天。当我遇到难题的时候会去玩游戏,当负责游戏的那部分大脑细胞极度亢奋的时候,负责编程的那部分大脑细胞就得到了充分的休息。当重新开始工作的时候,我会发现那些难题现在竟然可以迎刃而解。

5、对答案的渴求

  人类自然科学的发展史就是一个渴求得到答案的过程,即使只能知道答案的一小部分也值得我们去付出。只要你坚定信念,一定要找到问题的答案,你才会付出精力去探索,即使最后没有得到答案,在过程中你也会学到很多东西。

6、多与别人交流

  三人行必有我师,也许在一次和别人不经意的谈话中,就可以迸出灵感的火花。多上上网,看看别人对同一问题的看法,会给你很大的启发。

7、良好的编程风格

  注意养成良好的习惯,代码的缩进编排,变量的命名规则要始终保持一致。大家都知道如何排除代码中错误,却往往忽视了对注释的排错。注释是程序的一个重要组成部分,它可以使你的代码更容易理解,而如果代码已经清楚地表达了你的思想,就不必再加注释了,如果注释和代码不一致,那就更加糟糕。

8、韧性和毅力

  这也许是"高手"和一般程序员最大的区别。高手们并不是天才,他们是在无数个日日夜夜中磨炼出来的。成功能给我们带来无比的喜悦,但过程却是无比的枯燥乏味。你不妨做个测试,找个10000以内的素数表,把它们全都抄下来,然后再检查三遍,如果能够不间断地完成这一工作,你就可以满足这一条。

6/10/2005

FDD与XP的异同

Filed under: — site admin @ 6:25 pm

from Feature Driven Development and Extreme Programming

- Both processes are highly iterative and results oriented.
- Both people focused instead of document focused.
- Together with new tools and techniques are enabling and encouraging analysis, design, code, test and deployment to be done concurrently

[Team size]
XP is designed to work with projects that can be built by teams of two to ten programmers.
FDD was first used with a team of 16-20 developers of varying abilities, cultural backgrounds and experience.

[Metaphor and Model]
XP process begins with the Business writing stories on index cards. The whole project is guided by a system metaphor.
The enormous difference is FDD’s additional development of an overall domain object model. According to the car driving analogy, a domain object model is the map to guide the journey which can prevent you from driving around in endless circles. Reducing the time spent refactoring increases the time that can be spent adding new features.

[Collective Ownership or Class Ownership]
Collective ownership usually degenerates into non-ownership as the number of people involved grows.
Feature teams solve the problems that XP has mentioned, while keeping the well established benefits of individual code ownership:
- the feature team owns all the code that needs changing for a particular feature.
- The irritating development is caught at code inspection by the feature team and rejected.
- Owners of closely associated classes frequently work in the same feature team. Knowledge is clustered rather than randomly scattered.

[Inspections and Pair Programming]
XP uses pair programming to provide a continuous level of design and code inspection.
FDD promotes more formal inspections by feature teams. It is not unusual to see two members of a feature team working together where care is needed.

[Testing]
FDD takes unit testing almost for granted as part of Build By Feature. It is acceptable to use XP unit testing techniques in an FDD environment. FDD does not specify this because technology and resources differ so much between projects. In some circumstances it is very difficult to produce a set of completely isolated, independent tests that run in a reasonable amount of time.

[Reporting]
XP leaves tracking to the project managers, encouraging them to minimize the overhead of collecting data and use large visible wall charts.
Tracking By Feature in FDD describes a low-overhead, highly accurate means of measuring progress

6/9/2005

process, from forground to background

Filed under: — site admin @ 11:07 pm

A well-defined and lightweight process. Team members apply them several times, make refinements, and commit the process to memory. It becomes second nature to them. It becomes a good habit. It allows the team to carry out the basic steps, focusing on the content and results rather than process steps. The process itself moves from foreground to background.

软件过程的实践,应该是:经过若干次重复实践,而后精化,并逐渐形成记忆以成习惯。最终,要使得团队成员能够将注意力集中于结果与内容上,而非过程步骤本身;要使得过程规则从台前转入幕后。从规则到习惯,这是必由之路。由此也可以看到,好习惯的积累与传承,需要多次重复实践与磨合,需要所有团队成员的协作,这是十分难能可贵的。顾而,一个好的团队的形成,也并不是一件容易的事情。

What’s develper’s good feeling

Filed under: — site admin @ 12:16 am

Developers love new things. They get something new to work on every two weeks. They get closure every two weeks. Closure is an important must-have element for job satisfaction. Getting to declare “I’m done” every two weeks is such a good thing.

从FDD有关迭代的描述中我们可以看到,现代软件过程方法中对人的重视,这是一种人性的回归,不能忽略人的因素,不能忽略团队的士气,这也是很多时候为什么普通程序员对过重的文档化与管理制度会有漠视与抵触,job satisfaction才是能够为软件开发中的多数人所接受的good feeling,也是团队士气的关键因素——morale of team。

6/3/2005

关于团队对于软件过程的基本认同

Filed under: — site admin @ 11:43 am

[ 这里的文字来自于昨天在BJUG maillist中与网友Jerry lin讨论的关于敏捷方法的一点个人意见]

在一个摸索前行的XP团队中,部分XP实践都是在过程中不断积淀而来的。因而在对XP还没有多少实践体会之前,要求团队成员在多大程度上认同某种过程和制度,那是有疑问的,因为一切规则都还没有最终成形,团队也还没有找到适合自己的开发模式,何况XP也并未教授人们具体的行为细则。

不过,要说最基本的认同,XP,或者AM,有着"先天"的优势,那就是在它的"敏捷宣言"里提到的四点,这充分迎合了软件开发活动中的绝对主体——程序员们的口味。这是一个起点,而后,剩下的路都还要大家自己去走。

(昨天在sina上看到Martin Fowler北京之行的活动报道,面对主流媒体,还有高校与国家机构的负责人参加。我想,Martin Fowler的这次来华,对于中国软件开发的现状,以及敏捷方法在中国的推广和传播,或许是影响深远的:)

Powered by WordPress