<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title>5Dinfo</title>
<link>http://www.5dinfo.net/blog/</link>
<description>http://www.5dinfo.net/blog/</description>
<copyright>5Dinfo</copyright>
<generator>Ken Wu</generator>
<docs>http://blogs.law.harvard.edu/tech/rss</docs>
<item>
<title>King Forever</title>
<description><![CDATA[
<p><a href="http://5dinfo.net/blog/media/http_imgload.jpg" target="_blank" onclick="return hs.expand(this)"><img src="http://5dinfo.net/blog/media/http_imgload.jpg" border="0" alt="MJJ" title="MJJ" width="480" height="480" /></a></p><p>怀念Michael Jackson.</p><br /><br />
]]></description>
<link>http://www.5dinfo.net/blog/?2009/6/28/1</link>
<guid>http://www.5dinfo.net/blog/?2009/6/28/1</guid>
<category>Diary</category>
<author>吴迪 &lt;admin@5dinfo.net&gt;</author>
<pubDate>Sun, 28 Jun 2009 14:32:34 +0800</pubDate>
</item>
<item>
<title>Java API Design Guidelines</title>
<description><![CDATA[
<p>&nbsp;<span>Java API Design Guidelines</span><br /><span>by Eamonn McManus</span><br /><span>December 28, 2005</span></p><blockquote><p><strong>Summary</strong></p><p>There are tons of books and articles about how to design and write good Java code, but surprisingly little about the specific topic of API design. Here's a summary of what I've learnt on the subject from various sources and my own experience. </p></blockquote><br /><br /><p>I recently attended an excellent talk at <a href="http://www.javapolis.com/confluence/display/JP05/Home">JavaPolis</a>, <a href="http://www.elharo.com/">Elliotte Rusty Harold's</a> <a href="http://www.cafeconleche.org/slides/javapolis/xom/index.html"><em>XOM Design Principles</em></a>. Although the talk is nominally about XOM (an API for XML documentation manipulation), in fact more than half of it is about API design principles in general. This is a curiously neglected subject. There are tons of books and articles about how to design and write good Java code, but surprisingly little about the specific topic of API design. Yet with the proliferation of new Java APIs, whether through JSRs or through Open Source projects, this is an increasingly important subject.</p><p>I've been closely involved with the evolution of the <a href="http://java.sun.com/jmx/">JMX API</a> for over five years and have learnt a great deal about what works and what doesn't during that time. During the talk, I had the odd experience of continually wanting to cheer as Elliotte made point after point that I hugely agreed with.</p><p>I'm going to try to summarize here what I see as being the key points from this talk, from my own experience, and from a couple of other sources:</p><ul><li>An excellent tutorial on netbeans.org, <a href="http://openide.netbeans.org/tutorial/api-design.html"><em>How to Design a (module) API</em></a>. </li><li>A related NetBeans BOF at JavaOne 2005 by <a href="http://weblogs.java.net/blog/timboudreau/">Tim Boudreau</a> and <a href="http://www.netbeans.org/community/articles/interviews/yarda_tulach.html">Jaroslav Tulach</a>, entitled <a href="http://treefs.netbeans.org/files/documents/39/676/apidesign.sxi"><em>How to write APIs that will stand the test of time</em></a>. </li><li>Of course, Josh Bloch's <a href="http://java.sun.com/docs/books/effective/"><em>Effective Java</em></a> book. </li></ul><p>[<strong>Update:</strong> Although I was unaware of it when writing this blog entry, the <a href="http://lcsd05.cs.tamu.edu/slides/keynote.pdf">slides</a> referenced by Josh Bloch in a comment here cover some of the same ground and add much of interest.]</p><h2>Design to evolve</h2><p>If your API is worth anything, it will evolve over time. You should plan for this from the outset. A key part of the planning is to decide what sort of compatibility you will guarantee between revisions.</p><p>The best approach is to say that <strong>once something is in the API it will stay there</strong> and it will continue to work. Tweaking the API incompatibly between revisions will result in user reactions ranging from annoyance to murderous rage. The problem is particularly severe if your API ends up being used by different modules that are part of the same application. If Module 1 uses Commons Banana 1.0 and Module 2 uses Commons Banana 2.0 then life will be a whole lot easier if 2.0 is completely compatible with 1.0. Otherwise your users risk wasting huge amounts of time tweaking classpaths in a futile endeavour to make things work. They might end up having to play <a href="http://weblogs.java.net/blog/emcmanus/archive/2005/07/dealing_with_mu.html">mind-destroying games with class-loaders</a>, which is a clear signal that you have failed.</p><p>For APIs that are part of <a href="http://java.sun.com/j2se/index.jsp">Java SE</a>, we have an extreme form of compatibility. The aim is that <em>no code whatsoever</em> should break when you update from one version to the next. This means that <strong>classes and methods are never removed</strong>. It also means that we try to avoid changes that might break code that was depending on certain implementation details, even if the code shouldn't have been doing that.</p><p>The no-code-breakage rule applies to already-compiled code (<a href="http://jscstage.sfbay.sun.com/docs/books/jls/third_edition/html/binaryComp.html"><em>binary compatibility</em></a>). In some rare circumstances we might make changes that mean some existing code no longer compiles (<em>source compatibility</em>). For example, adding an overloaded method or constructor can sometimes produce ambiguity errors from the compiler when a parameter is null. We do try to find a way to avoid changes that break source compatibility in this way, but sometimes the best approach does imply that some source code might stop compiling. As an example, in Java SE 6 the <a href="http://download.java.net/jdk6/doc/api/javax/management/StandardMBean.html#StandardMBean%28T,%20java.lang.Class%29">constructors for javax.management.StandardMBean</a> have been generified. Some existing source code might conceivably stop compiling because it does not respect the constraints that are expressed using generics here, but that code is easily fixed by adding a cast, and the rare cases where that happens are outweighed by cases where the constraints will catch programming errors at compile time.</p><p>In general, <strong>you can't know what users of your API will do with it</strong>. When contemplating a change that <em>might</em> break existing code, you have to reason conservatively. Only if you can honestly say that it is next to impossible that a change will break code can you reasonably make it. You should certainly rule out completely a <em>signature change</em>, which basically means removing or renaming a visible method or class or changing the parameters of a visible method. (But you can remove a method if it overrides a method in a parent class without changing the parent method's semantics.)</p><p>Since the very earliest versions of your API are sure to have many mistakes in them, and you don't want to freeze those mistakes for all time, it's a good idea to <strong>bring out one or more 0.x versions</strong> before the 1.0 version. Users of these versions know that the API is unstable and won't curse you if it changes. Once you've brought out 1.0 you're committing to compatibility. For APIs that are developed through the <a href="http://jcp.org/">JCP</a>, these 0.x versions correspond to the phases before the final release (Early Draft Review, Public Review, Proposed Final Draft). If possible, it's a good idea to make an implementation of the API available at the same time as these intermediate specifications.</p><p>If at some stage you decide that there's really too much accumulated cruft from previous versions and you want to start over, then <strong>create a new API with different package names</strong>. Then code that uses the old version and code that uses the new version can co-exist easily.</p><h2>API design goals</h2><p>What should the design goals of your API be? Apart from compatibility, the following goals from Elliotte's presentation seem like an excellent set:</p><ul><li>It must be <strong>absolutely correct</strong>. In the case of XOM, this meant that the API could never produce malformed XML documents no matter what the caller did. For the JMX API, for example, it means that you can never get the MBean Server into an inconsistent state by registering strange MBeans in it or using funny ObjectNames or performing several operations concurrently. </li><li>It must be <strong>easy to use</strong>. This is hard to quantify. A good way to get an idea is to write lots of example code. Are there groups of operations that you keep having to repeat? Do you have to keep looking up your own API because you forget what things are called? Are there cases where the API doesn't do what you might expect? </li><li>It must be <strong>easy to learn</strong>. This overlaps considerably with ease of use. But there are some obvious principles to make learning easier. The smaller the API, the less there is to learn. Documentation should include examples. Where appropriate, the API should look like familiar APIs. </li><li>It must be <strong>fast enough</strong>. Elliotte was careful to put this in the list <em>after</em> the above items. Make sure the API is simple and correct. <em>Then</em> think about performance. You might be inclined to make API changes because the original API could only be implemented in an inefficient way. By all means change it to allow a more efficient implementation, <em>provided</em> you don't compromise correctness or simplicity. Don't rely on your intuition to know what performs well. <em>Measure</em>. Then tweak the API if you've determined that it really matters. </li><li>It must be <strong>small enough</strong>. This covers the size of the compiled code and especially the amount of memory it needs as it runs. The same principles as for speed apply. Make it simple and correct first; measure; and only <em>then</em> think about tweaking the API. </li></ul><h2>Be minimalist</h2><p>Because of the compatibility requirement, <strong>it's much easier to put things in than to take them out</strong>. So don't add anything to the API that you're not sure you need.</p><p>There's an approach to API design which you see depressingly often. Think of everything a user could possibly want to do with the API and add a method for it. Toss in protected methods so users can subclass to tweak every aspect of your implementation. Why is this bad?</p><ul><li><p><strong>The more stuff there is in the API, the harder it is to learn</strong>. Which classes and methods are the important ones? Which of the five different ways to do what I need is the best?</p><p>The situation is exacerbated by the Javadoc tool, which dumps all the classes in a package, and all the methods in a class, in an undifferentiated lump. We can expect that <a href="http://jcp.org/en/jsr/detail?id=260">JSR 260</a> will update the Javadoc tool to allow you to produce &quot;views&quot; of the API, and in that case fatter APIs will not be so overwhelming.</p></li><li><p><strong>The bigger the API, the more things can go wrong</strong>. The implementation isn't going to be perfect, but the same investment in coding and testing will yield better results for a smaller API.</p></li><li><p>If your API has more methods than it needs, then it's <strong>taking up more space than it needs</strong>.</p></li></ul><p>The right approach is to <strong>base the API on example code</strong>. Think of problems a user might want to solve with the API. Add just enough classes and methods to solve those problems. <strong>Code the solutions</strong>. Remove anything from the API that your examples don't need. This allows you to check that the API is useful. As a happy side-effect, it gives you some basic tests. And you can (and should) share the examples with your users.</p><h2>Interfaces are overvalued</h2><p>There's a certain style of API design that's very popular in the Java world, where everything is expressed in terms of Java interfaces (as opposed to classes). Interfaces have their place, but it is basically never a good idea for an entire API to be expressed in terms of them. <strong>A type should only be an interface if you have a good reason for it to be.</strong> Here's why:</p><ul><li><p><strong>Interfaces can be implemented by anybody</strong>. Suppose <a href="http://download.java.net/jdk6/doc/api/java/lang/String.html">String</a> were an interface. Then you could never be sure that a String you got from somewhere obeyed the semantics you expect: it is immutable; its hashCode() is computed in a certain way; its length is never negative; and so on. Code that used String, whether user code or code from the rest of the J2SE platform, would have to go to enormous lengths to ensure it was robust in the face of String implementations that were accidentally incorrect. And to even further lengths to ensure that its security could not be compromised by deliberately evil String implementations.</p><p>In practice, implementations of APIs that are defined entirely in terms of interfaces often end up cheating and casting objects to the non-public implementation class. DOM typically does this for example. So you can't give your own implementation of the <a href="http://download.java.net/jdk6/doc/api/org/w3c/dom/DocumentType.html">DocumentType</a> interface as a parameter to <a href="http://download.java.net/jdk6/doc/api/org/w3c/dom/DOMImplementation.html#createDocument%28java.lang.String,%20java.lang.String,%20org.w3c.dom.DocumentType%29">DOMImplementation.createDocument</a> and expect it to work. Then what's the point in having interfaces?</p></li><li><p><strong>Interfaces cannot have constructors or static methods</strong>. If you need an instance of an interface, you either have to implement it yourself, or you have to ask some other object for it. If <a href="http://download.java.net/jdk6/doc/api/java/lang/Integer.html">Integer</a> were an interface, then to get the Integer for a given int you could no longer use the obvious new Integer(n) (or, less obvious but still documented inside Integer, Integer.valueOf(n)). You would have to use IntegerFactory.newInteger(n) or whatever. This makes your API harder to understand and use.</p></li><li><p><strong>Interfaces cannot evolve</strong>. Suppose you add a new method to an interface in version 2 of your API. Then user code that implemented the interface in version 1 will no longer compile because it doesn't implement the new method. You can still preserve binary compatibility by catching <a href="http://download.java.net/jdk6/doc/api/java/lang/AbstractMethodError.html">AbstractMethodError</a> around calls to the new method but that is clunky. If you use an abstract class instead of an interface you don't have this problem. If you tell users not to implement the interface then you don't have this problem either, but then why is it an interface?</p></li><li><p><strong>Interfaces cannot be serialized</strong>. Java serialization has its problems, but you can't always get away from it. The JMX API relies heavily on serialization, for example. For better or worse, the way serialization works is that the name of the <em>actual implementation class</em> is serialized, and an instance of that exact same class is reconstructed at deserialization. If the implementation class is not a public class in your API, then you won't interoperate with other implementations of your API, and it will be very hard for you to ensure that you even interoperate between different versions of your own implementation. If the implementation class <em>is</em> a public class in your API, then do you really need the interface as well?</p></li></ul><p>Of course, there are sometimes good reasons for a type to be interface. Here are some common ones:</p><ul><li><p><strong>Callbacks</strong>. If the interface is intended to be implemented by user code, then it is often more appropriate than an abstract class. See <a href="http://download.java.net/jdk6/doc/api/java/lang/Runnable.html">Runnable</a> for example. This is mostly true of interfaces with just one method. Once there start being several methods you often find that an implementation class only needs to do something in one of them, and it's annoying to have to implement all the others. Furthermore if an interface has three methods today then you might want it to have four tomorrow, which is not usually possible as we saw. An abstract class can avoid these problems.</p></li><li><p><strong>Multiple inheritance</strong>. It is <em>occasionally</em> useful to be able to implement an interface deep in the inheritance hierarchy. A good example is <a href="http://download.java.net/jdk6/doc/api/java/lang/Comparable.html">Comparable</a>, where for example Integer is Comparable but its parent class Number is not. However, there aren't many other good examples of this in the core Java classes. It is usually bad practice to implement some random interface in a class whose primary purpose is something else. Implementing the interface in a private inner class is usually cleaner, and then of course it could just as well be an abstract class.</p></li><li><p><strong>Dynamic proxies</strong>. The invaluable <a href="http://download.java.net/jdk6/doc/api/java/lang/reflect/Proxy.html">java.lang.reflect.Proxy</a> class allows you to make an implementation of any interface at runtime, where calling any of the interface's methods results in a call to a single <a href="http://download.java.net/jdk6/doc/api/java/lang/reflect/InvocationHandler.html#invoke%28java.lang.Object,%20java.lang.reflect.Method,%20java.lang.Object%5B%5D%29">invoke</a> method. There's no way to construct a dynamic proxy for an abstract class, so if you think it will be useful for users to make dynamic proxies that is one reason to favour an interface. (<a href="http://cglib.sourceforge.net/">cglib</a> can sometimes be used to achieve the same effect for abstract classes, but with several limitations, plus the documentation is <a href="http://www.artima.com/weblogs/viewpost.jsp?thread=61979">really poor</a>.)</p></li></ul><h2>Be careful with packages</h2><p>The Java language has fairly limited ways of controlling the visibility of classes and methods. In particular, if a class or method is visible outside its package, then it is visible to all code in all packages. This means that if you define your API in several packages, you have to be careful to avoid being forced to make things public just so that code in other packages in the API can access them.</p><p>The simplest solution to avoid this is to <strong>put your whole API in one package</strong>. For an API with fewer than about 30 public classes this is usually the best approach.</p><p>If your API is too big for a single package to be appropriate, then you should plan to have <strong>private implementation packages</strong>. That is, some packages in your implementation are excluded from the Javadoc output and are not part of the public API, even though their contents are accessible. If you look at the JDK, for example, there are many sun.* and com.sun.* packages of this sort. Users who rely on the Javadoc output will not know of their existence. Users who browse the source code can see them, and can access the public classes and methods, but they are discouraged from doing so and warned that there is no guarantee that these classes will remain unchanged across revisions.</p><p>A good convention for private packages is to put internal in the name. So the Banana API might have public packages com.example.banana and com.example.banana.peel plus private packages com.example.banana.internal and com.example.banana.internal.peel.</p><p>Don't forget that the private packages are accessible. There may be security implications if arbitrary code can access these internals. Various techniques exist to address these. The NetBeans API tutorial <a href="http://openide.netbeans.org/tutorial/api-design.html#design.less.friend">describes one</a>. In the JMX API, we use another. There is a class <a href="http://download.java.net/jdk6/doc/api/javax/management/JMX.html">javax.management.JMX</a> which contains only static methods and has no public constructor. This means that user code can never have an instance of this class. So in the private com.sun.jmx packages, we sometimes add a parameter of type JMX to sensitive public methods. If a caller can supply a non-null instance of this class, it must be coming from the javax.management package.</p><h2>Other random tips</h2><p>Here are some other random tips based on our experience with the JMX API and on the sources I mentioned.</p><p><strong>Immutable classes are good</strong>. If a class can be immutable, then it should be. Rather than spelling out the reasons, I'll refer you to Item 13 in <a href="http://java.sun.com/docs/books/effective/"><em>Effective Java</em></a>. You wouldn't think of designing an API without having this book, right?</p><p><strong>The only visible fields should be static and final</strong>. Again this one is pretty banal and I mention it only because certain early APIs in the core platform violated it. Not an example to follow.</p><p><strong>Avoid eccentricity</strong>. There are many well-established conventions for Java code, with regard to identifier case, getters and setters, standard exception classes, and so on. Even if you think these conventions could have been better, don't replace them in your API. By doing so you force users to throw away what they already know and learn a new way of doing an old thing.</p><p>For instance, don't follow the bad example of <a href="http://download.java.net/jdk6/doc/api/java/nio/package-summary.html">java.nio</a> and <a href="http://download.java.net/jdk6/doc/api/java/lang/ProcessBuilder.html">java.lang.ProcessBuilder</a> where the time-honoured T&nbsp;getThing() and void&nbsp;setThing(T) methods are replaced by T&nbsp;thing() and ThisClass&nbsp;thing(T). Some people think this is neato-keen and others that it is an abomination, but either way it's not a well-known idiom so don't force your users to learn it.</p><p><strong>Don't implement Cloneable</strong>. It is usually less useful than you might think to create a copy of an object. If you do need this functionality, rather than having a clone() method it's generally a better idea to define a &quot;copy constructor&quot; or static factory method. So for example class Banana might have a constructor or factory method like this:</p><pre>      public Banana(Banana b) {      // copy constructor     	  this(b.colour, b.length);       }       // ...or...       public static Banana newInstance(Banana b) {     	  return new Banana(b.colour, b.length);       }     </pre><p>The advantage of the constructor is that it can be called from a subclass's constructor. The advantage of the static method is that it can return an instance of a subclass or an already-existent instance.</p><p>Item 10 of <em>Effective Java</em> covers clone() in excruciating detail.</p><p><strong>Exceptions should usually be unchecked</strong>. Item 41 of <em>Effective Java</em> gives an excellent summary here. Use a checked exception &quot;if the exceptional condition cannot be prevented by proper use of the API <em>and</em> the programmer using the API can take some useful action once confronted with the exception.&quot; In practice this usually means that a checked exception reflects a problem in interaction with the outside world, such as the network, filesystem, or windowing system. If the exception signals that parameters are incorrect or than an object is in the wrong state for the operation you're trying to do, then an unchecked exception (subclass of <a href="http://download.java.net/jdk6/doc/api/java/lang/RuntimeException.html">RuntimeException</a>) is appropriate.</p><p><strong>Design for inheritance or don't allow it</strong>. Item 15 of <em>Effective Java</em> tells you all you might want to know about this. The summary is that every method should be final by default (perhaps by virtue of being in a final class). Only if you can clearly document what happens if you override the method should it be possible to do so. And you should only do that if you have coded useful examples that do override the method.</p><h2>Summary</h2><ul><li>Design to evolve. </li><li>Correctness, then simplicity, then efficiency. </li><li>Interfaces are overvalued. </li><li>Be careful with packages. </li><li>Read <em>Effective Java</em>. </li></ul><p><a href="http://www.artima.com/weblogs/viewpost.jsp?thread=142428" target="_blank">http://www.artima.com/weblogs/viewpost.jsp?thread=142428</a> </p>
]]></description>
<link>http://www.5dinfo.net/blog/?2008/11/8/1</link>
<guid>http://www.5dinfo.net/blog/?2008/11/8/1</guid>
<category>Software Design</category>
<author>吴迪 &lt;admin@5dinfo.net&gt;</author>
<pubDate>Sat, 08 Nov 2008 02:02:33 +0800</pubDate>
</item>
<item>
<title>IndexReader被缓存与未被缓存的搜索性能测试对比</title>
<description><![CDATA[
<p>索引个数: 10<br />索引大小: 59.6G,未作optimize.<br />索引总记录数: 17412072 (一千七百万)</p><p>未缓存,<br />第一次查询耗时: 80266毫秒<br />第二次查询耗时: 17141毫秒<br />第三次查询耗时: 17438毫秒<br />第四次查询耗时: 17875毫秒<br />第五次查询耗时: 16406毫秒<br />第六次查询耗时: 16953毫秒</p><p>缓存后,<br />第一次查询耗时: 1分58秒875毫秒<br />第二次查询耗时: 4秒437毫秒<br />第三次查询耗时: 3秒15毫秒<br />第四次查询耗时: 2秒906毫秒<br />第五次查询耗时: 2秒890毫秒</p><br /><br />
]]></description>
<link>http://www.5dinfo.net/blog/?2008/10/30/1</link>
<guid>http://www.5dinfo.net/blog/?2008/10/30/1</guid>
<category>JAVA</category>
<author>吴迪 &lt;admin@5dinfo.net&gt;</author>
<pubDate>Thu, 30 Oct 2008 10:11:57 +0800</pubDate>
</item>
<item>
<title>祝福</title>
<description><![CDATA[
<p><img src="http://5dinfo.net/MyPhoto/photo/5dinfo_2008100420575884343.jpg" border="0" width="196" height="223" /></p><p>祝新婚愉快.</p><br /><br />
]]></description>
<link>http://www.5dinfo.net/blog/?2008/10/4/1</link>
<guid>http://www.5dinfo.net/blog/?2008/10/4/1</guid>
<category>Diary</category>
<author>吴迪 &lt;admin@5dinfo.net&gt;</author>
<pubDate>Sat, 04 Oct 2008 21:00:29 +0800</pubDate>
</item>
<item>
<title>Nokia E66</title>
<description><![CDATA[
<p><a href="http://5dinfo.net/MyPhoto/photo/5dinfo_2008092015030043820.jpg" target="_blank" onclick="return hs.expand(this)"><img src="http://5dinfo.net/MyPhoto/PreviewImage/2008-09/pre5dinfo_2008092015030043820.jpg" border="0" alt="E66" title="E66" width="180" height="101" /></a></p><p>&nbsp;多了个玩具.</p><br /><br />
]]></description>
<link>http://www.5dinfo.net/blog/?2008/9/20/1</link>
<guid>http://www.5dinfo.net/blog/?2008/9/20/1</guid>
<category>Diary</category>
<author>吴迪 &lt;admin@5dinfo.net&gt;</author>
<pubDate>Sat, 20 Sep 2008 23:37:00 +0800</pubDate>
</item>
<item>
<title>十年</title>
<description><![CDATA[
<p>1998-2008</p><p>十年后我们相聚北京. </p><br /><br />
]]></description>
<link>http://www.5dinfo.net/blog/?2008/9/1/1</link>
<guid>http://www.5dinfo.net/blog/?2008/9/1/1</guid>
<category>Diary</category>
<author>吴迪 &lt;admin@5dinfo.net&gt;</author>
<pubDate>Mon, 01 Sep 2008 10:59:47 +0800</pubDate>
</item>
<item>
<title>万物皆规律,有法天下和 -- 怎样做研究</title>
<description><![CDATA[
<p><strong><a href="http://blog.sina.com.cn/s/blog_4cbec5e9010007pm.html" target="_blank">怎样做研究（一）</a></strong></p><p><strong><a href="http://blog.sina.com.cn/s/blog_4cbec5e9010007pl.html" target="_blank">怎样做研究（二）</a></strong></p><br /><br />
]]></description>
<link>http://www.5dinfo.net/blog/?2008/8/18/1</link>
<guid>http://www.5dinfo.net/blog/?2008/8/18/1</guid>
<category>Programming Life</category>
<author>吴迪 &lt;admin@5dinfo.net&gt;</author>
<pubDate>Mon, 18 Aug 2008 00:19:26 +0800</pubDate>
</item>
<item>
<title>又迟到了</title>
<description><![CDATA[
MD, 又迟到了,我起来的那会, 姚明正在天安门前传递圣火. 他咋起得这么早咧?<br /><br />
]]></description>
<link>http://www.5dinfo.net/blog/?2008/8/6/1</link>
<guid>http://www.5dinfo.net/blog/?2008/8/6/1</guid>
<category>Diary</category>
<author>吴迪 &lt;admin@5dinfo.net&gt;</author>
<pubDate>Wed, 06 Aug 2008 11:05:29 +0800</pubDate>
</item>
<item>
<title>Christian The Lion</title>
<description><![CDATA[
<p>Love knows no limits and Boolean.TRUE friendship last a lifetime.</p><p>Get back in touch with some one today.</p><br /><br /><div><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" width="425" height="344"><param name="width" value="425" /><param name="height" value="344" /><param name="allowfullscreen" value="true" /><param name="src" value="http://www.youtube.com/v/oiGKWoJi5qM&amp;hl=en&amp;fs=1" /><embed type="application/x-shockwave-flash" width="425" height="344" allowfullscreen="true" src="http://www.youtube.com/v/oiGKWoJi5qM&amp;hl=en&amp;fs=1"></embed></object></div>
]]></description>
<link>http://www.5dinfo.net/blog/?2008/7/28/1</link>
<guid>http://www.5dinfo.net/blog/?2008/7/28/1</guid>
<category>Diary</category>
<author>吴迪 &lt;admin@5dinfo.net&gt;</author>
<pubDate>Mon, 28 Jul 2008 21:55:20 +0800</pubDate>
</item>
<item>
<title>[转]系统架构师的修炼</title>
<description><![CDATA[
<p style="font-size: 8pt"><span style="font-size: 10pt"></span></p><h3 style="font-size: 12pt">首先，何谓系统架构师？</h3><p>&nbsp;IBM工程师的说明是：<br />&nbsp;&nbsp;架构师的主要责任是提供开发人员和项目经理之间的共用沟通媒体。他们负责让业务规则及需求与工程实践及限制相适应，以确保成功</p><p>&nbsp;中文Wiki上的说明是：<br />&nbsp;&nbsp;系统架构师负责设计系统整体架构，从需求到设计的每个细节都要考虑到，把握整个项目，使设计的项目尽量效率高，开发容易，维护方便，升级简单</p><p>&nbsp;这两个解释，加起来基本说明了系统架构师的定义。</p><h3><br />&nbsp;</h3><br /><br />JAVA系统架构师应该看的几本书 <p>Thinking in Java<br />Effective Java</p><p>UML基础、案例与应用 <br />UML入门提高</p><p>软件工匠<br />设计模式--可复用面向对象软件的基础</p><p>重构-改善既有代码的设计<br />敏捷软件开发-原则、模式、实践</p><p>企业应用架构模式<br />Expert One-on-One J2EE Development without EJB <br />&nbsp;<br />软件工程--实践者的研究方法<br />软件领导－－成功开发软件的指导准则</p><p>后面的两本书，其实已经有点属于项目经理的范畴了，不过还不是很深入，看看对做成功的系统架构师是很有好处。</p><h3>企业应用的系统架构师应该关注的几个方面</h3><p>数据持久层的设计<br />&nbsp;在Spring和Hibernate，ibatis出来以前，几乎每家公司都有自己的一套方法和架构，而架构师的50％的精力也会集中到这上面，EJB只是增加架构师的负担。在Spring出来以后，基本上，大多数的架构师都从重复设计这个轮子的无用功中解脱出来了。Rod的轮子太好用了，基本上，大家只要套上去就行了，或者，剩下最重要的事情，是选择一个合适的数据库连接池的开源项目吧</p><p>MVC架构的具体设计<br />&nbsp;MVC只是个概要的概念，具体如何实现的具体技术很多，根据项目设计最恰当的架构</p><p>大并发性访问<br />&nbsp;使用缓存，在数据量达到一定程度时，使用集群技术，优先考虑利用服务器的集群，其次是硬件集群，最后才是应用本身加入集群功能</p><p>超大数据量返回结果<br />&nbsp;尽量使用分页，优化SQL语句，循环处理数据时尽可能共用对象，只保留关键数据，及时释放内存占用</p><p>超大文件的读取和生成<br />&nbsp;尽可能快的读取大文件，并进行分析。写入大文件时，如何及时释放内存。学会适当利用操作系统的命令行资源来更快完成任务。<br />&nbsp;<br />多线程的应用和管理<br />&nbsp;线程池的管理和监控，线程的启动（包括定时启动），结束，回收，线程资源的释放<br />&nbsp;<br />用户界面可用性设计<br />&nbsp;平衡速度和可用性，恰当的使用异步和同步技术，展现关键数据为重点</p><p>分布式的数据交流和集成<br />&nbsp;选择恰当的数据交互方式，从最泛滥低效的Web Service到最实用的文件共享</p><p>群集系统的管理<br />&nbsp;如何确保缓存的同步？如何确保对象唯一性？如何保证各台机器的同步？<br />&nbsp;是否采用EJB?如何利用J2EE的特性（例如JNDI)</p><p>复杂的业务规则<br />&nbsp;规则引擎和工作流引擎场景和应用<br />&nbsp;<br />其实，作为一个真正的系统架构师，不应该局限于企业应用的系统，这种系统往往有数据库的局限性，有时候，应该考虑是否可以横向跨越，直接对其它系统做一些架构考虑，在没有丰富的实战经验的前提下，而只是看了其它人的系统和代码，就能够给出有效的设计指导。</p><p>例如对于一个下载软件，可以有如下考虑：</p><p>&nbsp;1.&nbsp;未明和非法url的检验，已经下载失败的容许，信息记录<br />&nbsp;2.&nbsp;多线程下载一个文件,文件的切分和拼合，部分切片丢失的拼合可能性<br />&nbsp;3.&nbsp;下载线程管理<br />&nbsp;4.&nbsp;服务器或者P2P的机器之间的通讯协议<br />&nbsp;5.&nbsp;速度监控和限制<br />&nbsp;6.&nbsp;下载进度的监控和显示</p><p>作为一个在线播放软件,可以做如下考虑</p><p>&nbsp;1.&nbsp;播放速度的保证<br />&nbsp;&nbsp;&nbsp;机器的问题基本不存在了，关键是网络问题。如何在检测网络速度，根据影片的质量，并缓冲足够多的内容，保证播放一直尽可能顺利的完成。</p><p>&nbsp;2.&nbsp;播放质量的保证<br />&nbsp;&nbsp;&nbsp;如何利用DirectX等技术,最快的进行渲染,是自己写底层,还是利用已有的API</p><p>由于没做过类似的项目，可以写的东西还是少很多了。</p><h3>系统架构师应该有的素质：</h3><p>1、&nbsp;实际的编程经验<br />&nbsp;&nbsp;最少2年吧，多了就不说了，其实从大学就开始钻研的话，</p><p>2、&nbsp;书面表达能力和口头交流能力<br />&nbsp;&nbsp;&nbsp;综合利用架构图，UML图，文字和代码片断，表达自己设计思想，至于是Word还是ppt，应该通吃</p><p>&nbsp;&nbsp;在开发人员中发现架构师的最有价值标准是有效的沟通。您需要技术娴熟、经验丰富的开发人员，这样的人员需要有就项目中的业务相关问题进行沟通的经历。架构师经常必须对理解方面的差距进行预计，然后才能有所贡献。他们必须愿意克服困难来确保技术和业务观点的融合。他们并不必对意见交换工作进行计划和协调;这仍然主要是项目经理的工作。他们的任务是确定表述系统设计时的最佳工具和构件，以促进有效的意见交换。他们必须能够判断当前方法显得不足而需要采用新方法的情况。写作技能也非常重要，还需要具有制作草图的技能或使用制图软件的能力。</p><p>&nbsp;3、&nbsp;自觉主动;积极解决设计问题<br />&nbsp;&nbsp;架构师的日常工作目标经常并不明确。很多开发人员直接参考功能规范来列出任务清单。架构师通常则是向这些开发人员提供所需结构的人员，以便尽可能提高工作效率。好的候选者不仅进行沟通方面的工作，而且也会预计各种设计问题并加以解决--通常在没有任何具体指示的情况下自觉进行。无论所分配的职责如何，积极参与项目的开发人员都有机会从一起工作的人员中脱颖而出。</p><p>4、&nbsp;抽象思维能力和总结能力<br />&nbsp;&nbsp;架构师，顾名思义，在系统未搭建好之前，就要能够有一个草图在心。而如果是对现有系统的改造，那么能在看过系统的文档（如果有的话）和代码后，就能总结出系统的架构特点。<br />&nbsp;&nbsp;架构师必须能够理解表述模糊的概念并将其变成相关各方能够理解的项目构件。他们必须能够理解抽象概念，并以具体的语言对其进行沟通。开发人员中好的候选者经常要求或自己主动解释开发生命周期中容易混淆的问题。他们能迅速评估各种想法并将其纳入后续工作的操作建议中。</p><p>&nbsp;&nbsp;开发人员经常具有很强的数学能力，而好的架构师则倾向于表现出更强的口头表达能力。管理人员经常说开发人员具有&quot;工程意识&quot;，而这是一个用于评估架构师的非常有意义的方面。架构师应该具有很强的解决技术问题的能力，但还必须能够准确获知更为全面的人员如何与技术交互的信息。这要求具有某种形式的抽象思维(而不再是代码的细节)，这种思维能力可能较难形成。</p><p>5、&nbsp;全面的技术资讯吸收能力和选择鉴别能力<br />&nbsp;&nbsp;作为开发人员出身，对于某一个具体问题的研究能力（虽然很多人总结为google能力），已经相当具备了。但是对技术资讯的全面接受和选择性深入了解能力，并且做出正确的判断，那些技术无非是厂家的噱头，而那些技术是真正可以用到项目，提高项目质量的好技术，这种能力确实至关重要的。</p><p><a href="http://www.kuqin.com/pragmatic/20070821/542.html">http://www.kuqin.com/pragmatic/20070821/542.html</a> </p>
]]></description>
<link>http://www.5dinfo.net/blog/?2008/7/20/1</link>
<guid>http://www.5dinfo.net/blog/?2008/7/20/1</guid>
<category>Programming Life</category>
<author>吴迪 &lt;admin@5dinfo.net&gt;</author>
<pubDate>Sun, 20 Jul 2008 22:37:20 +0800</pubDate>
</item>
</channel>
</rss>
