yangxiang

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  8 随笔 :: 0 文章 :: 73 评论 :: 0 Trackbacks

2009年8月11日 #

[英文出处]:21 Laws of Computer Programming
[译文出处]:外刊IT评论


任何一个有经验的程序员都知道,软件开发遵循着一些不成文的法则。然而,如果你不遵循这些法则也并不意味着会受到惩罚;相反,有时你还会获得意外的好处。下面的就是软件编程中的21条法则:

  1. 任何程序一旦部署即显陈旧。
  2. 修改需求规范来适应程序比反过来做更容易。
  3. 一个程序如果很有用,那它注定要被改掉。
  4. 一个程序如果没用,那它一定会有很好的文档。
  5. 任何程序里都仅仅只有10%的代码会被执行到。
  6. 软件会一直膨胀到耗尽所有资源为止。
  7. 任何一个有点价值的程序里都会有至少一个bug。
  8. 原型完美的程度跟审视的人数成反比,反比值会随着涉及的资金数增大。
  9. 软件直到被变成产品运行至少6个月后,它最严重的问题才会被发现。
  10. 无法检测到的错误的形式无限多样,而能被检测到的正好相反,被定义了的十分有限。
  11. 修复一个错误所需要投入的努力会随着时间成指数级增加。
  12. 软件的复杂度会一直增加,直到超出维护这个程序的人的承受能力。
  13. 任何自己的程序,几个月不看,形同其他人写的。
  14. 任何一个小程序里面都有一个巨大的程序蠢蠢欲出。
  15. 编码开始的越早,花费的时间越长。
  16. 一个粗心的项目计划会让你多花3倍的时间去完成;一个细心的项目计划只会让你多花2倍的时间。
  17. 往大型项目里添加人手会使项目更延迟。
  18. 一个程序至少会完成90%,但永远完成不了超过95%。
  19. 如果你想麻烦被自动处理掉,你得到的是自动产生的麻烦。
  20. 开发一个傻瓜都会使用的软件,只有傻瓜愿意使用它。
  21. 用户不会真正的知道要在软件里做些什么,除非使用过。
posted @ 2010-09-30 09:50 『 Y X 』 阅读(244) | 评论 (0)编辑 收藏

Eclipse快捷键按了没有反应可能是和其他程序设置的快捷键冲突了,如果确认没有冲突,可以看看是不是如下问题。

在工具栏(Toolbars)上面点击右键,选择“Customize Perspective...”

看看Command Group Availability 里面有没有勾选你所设置的快捷键的分组,如果没有就勾上,再试试快捷键能否使用。


posted @ 2010-08-24 09:55 『 Y X 』 阅读(3418) | 评论 (0)编辑 收藏

    当为遗留系统加入spring时,经典问题就是遗留系统需要引用spring管理的bean。幸好spring有机制可以处理这些。

    建一个类实现ApplicationContextAware接口,有一个引用ApplicationContext的静态成员,然后,遗留系统需要引用spring管理的bean的地方,使用这个类。

1.比如:我这里建一个SpringContext类

package net.blogjava.chenlb;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
 * 此类可以取得Spring的上下文.
 * Spring 使new方法创建的对象可以引用spring管理的 bean.
 * 2007-10-18 上午11:12:33
 * 
@author chenlb
 
*/
public class SpringContext implements ApplicationContextAware {

    
protected static ApplicationContext context;
    
    
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        context 
= applicationContext;
    }

    
public static ApplicationContext getContext() {
        
return context;
    }
}


2.然后在spring配置文件里加

<bean id="springContext" class="net.blogjava.chenlb.SpringContext"></bean>


3.其它类中引用

MyBean myBean = (MyBean) SpringContext.getContext().getBean("myBean");


4.如果老是写SpringContext.getContext().getBean("...");麻烦,可以建一个工厂类来返回你要 的bean

package net.blogjava.chenlb;

public class MyServerFactory {

    
public static MyBean1 getMyBean1() {
        
return (MyBean1) SpringContext.getContext().getBean("myBean1");
    }
}



原文:http://chenlb.javaeye.com/blog/135897

posted @ 2010-06-15 19:22 『 Y X 』 阅读(294) | 评论 (0)编辑 收藏

<%@ page import="org.springframework.web.context.support.WebApplicationContextUtils" %>
<%@ page import="org.springframework.web.context.WebApplicationContext" %>
<%
    WebApplicationContext context =    WebApplicationContextUtils.getRequiredWebApplicationContext(this.getServletContext());
    SomeBean bean=(SomeBean)context.getBean(SomeBean.class);
%>

posted @ 2010-06-15 19:18 『 Y X 』 阅读(406) | 评论 (0)编辑 收藏

1、xml.xml
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="xsl.xsl"?>
<book>
    
<title>XML与JSP</title>
    
<chapter>
        
<title>第1章 认识XML与DTD</title>
        
<section>
            
<title>XML的产生</title>
            
<example>HelloWorld.html</example>
        
</section>
    
</chapter>
    
<chapter>
        
<title>第2章 XML名称空间</title>
        
<section>
            
<title>名称空间在元素和属性中的应用</title>
            
<section>
                
<title>名称空间在元素中的应用</title>
                
<example>people.xml</example>
            
</section>
            
<section>
                
<title>缺省名称空间</title>
                
<example>book.xml</example>
            
</section>
            
<section>
                
<title>名称空间在属性中的应用</title>
                
<example>book2.xml</example>
            
</section>
        
</section>
        
<section>
            
<title>名称空间和DTD</title>
        
</section>
    
</chapter>
</book>

2、xsl.xsl
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    
<xsl:output method="html" version="1.0" encoding="utf-8" standalone="yes"/>
    
<xsl:template match="/">
        
<html>
            
<head>
                
<title>使用XML+XSLT生成的HTML文件</title>
            
</head>
            
<body>
                
<xsl:apply-templates select="book"/>
            
</body>
        
</html>
    
</xsl:template>
    
<xsl:template match="chapter">
        
<br/>
        
<br/>
        
<xsl:value-of select="./title"/>
        
<xsl:apply-templates select="./section"/>
    
</xsl:template>
    
<xsl:template match="chapter/section">
        
<br/>
        
<br/>
        
<xsl:text>    </xsl:text>
        
<!--<xsl:number format="1. " level="multiple"/>-->
        
<xsl:number format="1. " level="multiple" count="chapter | section" from="book"/>
        
<xsl:value-of select="./title"/>
        
<xsl:apply-templates select="./section"/>
    
</xsl:template>
    
<xsl:template match="chapter/section/section">
        
<br/>
        
<br/>
        
<xsl:text>        </xsl:text>
        
<!--<xsl:number format="1. " level="multiple"/>-->
        
<xsl:number format="1. " level="multiple" count="chapter | section" from="book"/>
        
<xsl:value-of select="./title"/>
        
<xsl:number value="123456789" grouping-separator="," grouping-size="3"/>
    
</xsl:template>
</xsl:stylesheet>

3、java.java
package test;

import java.io.File;
import java.io.IOException;

import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;

import org.junit.Test;

public class Train {
    @Test
    
public void test() throws IOException {
        String xmlFileName 
= "d:/test/xml.xml";
        String xslFileName 
= "d:/test/xsl.xsl";
        String htmlFileName 
= "d:/test/html.html";
        Train.Transform(xmlFileName, xslFileName, htmlFileName);
    }

    
public static void Transform(String xmlFileName, String xslFileName,
            String htmlFileName) {
        
try {
            TransformerFactory tFac 
= TransformerFactory.newInstance();
            Source xslSource 
= new StreamSource(xslFileName);
            Transformer t 
= tFac.newTransformer(xslSource);
            File xmlFile 
= new File(xmlFileName);
            File htmlFile 
= new File(htmlFileName);
            Source source 
= new StreamSource(xmlFile);
            Result result 
= new StreamResult(htmlFile);
            System.out.println(result.toString());
            t.transform(source, result);
        } 
catch (TransformerConfigurationException e) {
            e.printStackTrace();
        } 
catch (TransformerException e) {
            e.printStackTrace();
        }
    }
}

4、html.html
<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>使用XML+XSLT生成的HTML文件</title>
</head>
<body>
    XML与JSP
    
<br>
<br>第1章 认识XML与DTD<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;1.1. XML的产生
    
<br>
<br>第2章 XML名称空间<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;2.1. 名称空间在元素和属性中的应用<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2.1.1. 名称空间在元素中的应用123,456,789<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2.1.2. 缺省名称空间123,456,789<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2.1.3. 名称空间在属性中的应用123,456,789<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;2.2. 名称空间和DTD
</body>
</html>

5、效果
XML与JSP

第1章 认识XML与DTD

    1.1. XML的产生

第2章 XML名称空间

    2.1. 名称空间在元素和属性中的应用

        2.1.1. 名称空间在元素中的应用123,456,789

        2.1.2. 缺省名称空间123,456,789

        2.1.3. 名称空间在属性中的应用123,456,789

    2.2. 名称空间和DTD

posted @ 2009-08-11 17:05 『 Y X 』 阅读(5033) | 评论 (1)编辑 收藏