《Effective Java》: Joshua Bloch访谈

   原文地址Effective Java: An Interview with Joshua Bloch
   翻  译Eastsun

   The most anticipated book among Java developers over the past few years has been the second edition of Effective Java by Joshua Bloch. The book was finally launched during JavaONE this year. I caught up with Josh and discussed the book, the changes in industry since the last edition and his thoughts on closures.
  在最近几年来,Java开发者最期待的技术书籍莫过于Joshua Bloch的《Effective Java》第二版了。该书在今年的JavaOne大会上正式发布。我( Eastsun注:指James Sugrue)对Josh进行了采访,我们谈到了这本书,自从上一版以来业界发生的变化以及他对闭包的看法。

   James Sugrue: The book was made available at JavaONE. Did you do any technical sessions to coincide with the release?
   James Sugrue: 这本书是在JavaOne大会上发布的,你是否做了一些技术讲座以配合这个发布?
   Joshua Bloch: I did two sessions. On was directly related to the book. It was called "More Effective Java." It was largely devoted to enum types (Items 30-34, 77), but also included a mnemonic for the use of bounded wildcard types (Item 28) and a guide to lazy initialization (Item 71).
   Joshua Bloch: 我有两个讲座。一个与这本书直接相关,叫做"More Effective Java"。主要是关于枚举类型(条目 30-34, 77),以及一些关于如何使用通配符(条目 28)。还有一个关于延迟初始化的讲座。(条目 71)

   Sugrue: What changes have been added to bring to book up to date?
   Sugrue: 在该书的新版中有那些变化?
   Bloch: I added two chapters, one on Generics, and another on Enums and Annotations. Also I added items describing best practices for each of the new language features in Java 5 (for-each loop, autoboxing, varargs, static import). I changed the title of the Threads chapter to Concurrency and rewrote it to reflect programming in the java.util.concurrent era (where the basic abstractions are tasks and executors, rather than threads, wait and notify). There's a table on page 1 that points you to all of this material.

In addition to adding material on features that were added to the platform since the first edition of the book, I added items or modified existing ones to reflect the evolution of best practices. For example, I added an item describing the Builder pattern (Item 2), and one describing the Serialization Proxy pattern (Item 78). I went over every line of every item, and did my best to make sure they were up to date.

   Bloch: 我增加了两章。一章是关于泛型,另一章是关于Enum与Annotation;还增加了一些讲述Java5中新增的语言特性最佳实践的条目。我将Threads一章的标题修改为Concurrency,并且针对java.util.concurrent重写了该章。在该书的第一页有一个列表指出了这些变化。
  除了自该书第一版以来Java平台上新添的特性以外,我还增加或修改了一些条目以反映最佳实践的演化。譬如,我增加了一个讲述Builder模式的条目(条目 2)以及一个讲述Serialization Proxy模式的条目(条目 78)。我仔细检查了书里面的每一条的每一行,尽我最大的努力确保它们反映出当前最新的变化。

   Sugrue: Is it fair to consider this as a whole new book?
   Sugrue: 我们是否可以把它看做全新的一本书?
   Bloch: No! I did my best not to change the character of the work. I hope it feels like an old friend to readers of the first edition.
   Bloch: 不,恰恰相反。我尽量不改变这本书的整体感官,我希望第一版的读者看到该书时就像遇到了老朋友。

   Sugrue: Since the first book in 2001, what key changes have you observed in Java development?
   Sugrue: 自从2001年发布该书的第一版以来,你认为在Java开发领域有那些关键性的变化?
   Bloch: The biggest changes are the rise of modern IDEs, such as Eclipse, IntelliJ, and NetBeans, and static analysis tools, such as FindBugs. Agile techniques, which were just making inroads in 2001, have become mainstream.
   Bloch: 最大的变化是现代IDE的增长,例如Eclipse、IntelliJ以及Netbeans。还有静态分析工具,如FindBugs。敏捷技术在2001年的时候才刚刚起步,而现在已经成为主流。

   Sugrue: Effective Java is seen as one of the most important books for Java. Considering it's popularity, were you wary of making any changes to such a well established book?
   Bloch: Very much so. That's why I tried so hard not to change the character of the book. Of course I had to cover all of the new material, and I had to critically examine everything I said in the first edition. But I did everything in my power to make sure that nothing got hurt in the process. I hope I succeeded, but I won't know for sure until I've heard from readers of the second edition.

   Sugrue: Every developer should read this book - but some might not be able to make time. For those, if you were to promote just one message from the book what would it be?
   Sugrue: 每一个Java开发者都应该阅读这本书,但可能有一些人没有充裕的时间。对于这些人,你能否简单介绍一下你这本书的主旨?
   Bloch: I was asked the same question the very first time I was interviewed about Effective Java, back in June 2001. This is what I replied: Always strive to write simple, clear, and correct programs. It is penny wise and pound foolish to do otherwise. Style does matter. It pays real dividends in terms of correctness, usability, robustness, and maintainability. Also, it's way more fun to write good programs than bad ones.
  I still believe every word.

   Bloch: 我第一次被采访关于《Effective Java》的时候也被问到了这个问题,那还是2001年。这是我当时的回答:力求写简单、清晰、正确的代码,而不是其它。代码风格很重要,它能在团队中对代码的正确性、可用性、鲁棒性以及可维护性产生实际的效用。同样,写好的代码比差的代码可以带来更多的快乐。
  我依然坚信这些。

   Sugrue: What is the most common fault in Java developers in your opinion?
   Sugrue: 你认为Java开发者普遍易犯的错误是什么?
   Bloch: Like most programmers, we have a natural tendency to optimize our code even when we should know better. Our attempted optimizations don't always make the code run faster. Sometimes they just make it more complicated.
   Bloch: 大多数程序员都有一个自然的倾向,在开始写代码时就试图优化以提高性能。但我们这种企图并不总是有用,甚至在某些时候只会把程序复杂化。

   Sugrue: The book includes hints for class and interface design. In one paragraph, can you describe a guideline for a good design?
   Sugrue: 这本书里有一些关于类与接口设计的建议。你能否简单的讲述一下你对于良好设计的指导准则?
   Bloch: I apologize if this sounds trite, but each class should do one thing, and do it well. There's a great litmus test: can you, in one short, clear noun phrase, describe what an instance of the class represents? If not, you should probably spend more time thinking about the design.
   Bloch: 我讲的东西可能没有什么新意,那就是每一个类只应该做一件事情,并且把它做好。这儿有一个很好的检验方法:你能否用一个简短的、明了的名词短语描述这个类的实例所代表的东西?如果不能,那你可能需要多花一些时间考虑一下你的设计了。

   Sugrue: Scripting on top of the JVM has become very popular over the past year or so. What do you think of it?
   Sugrue: 在这些年来,JVM上的动态语言变得流行起来。你是怎么看待这个现象呢?
   Bloch: I'm a pragmatist. Often it's the easy way to get things done, and that makes it good. Of course you should write your scripts with all the care that you write your programs, because they'll have to be maintained in parallel with the programs.
   Bloch: 我是个实用主义者。使用动态语言通常使解决问题变得更加容易,这很好。当然使用动态语言也要注意一些问题,因为它们需要与其他代码共同被维护。

   Sugrue: What is your opinion on the inclusion Closures in Java 7?
   Sugrue:  你如何看待Java7中将要引入的闭包?
   Bloch: As readers of the first edition know, I value simplicity and clarity above all else. So it should come as no surprise that I don't want to see anymore major additions to the Java programming language. It's already as complex as a language should be. If Java programmers want to use features that aren't present in the language, I think they're probably best off using another langauge that targets the JVM, such a Scala and Groovy.
   Bloch: 正如该书第一版读者所了解的那样,我一直将简洁与清晰放到首要位置。因此我不希望看到Java在语言上有太大的变化,Java语言现在已经很好,不应该变得更加复杂。如果Java程序员想使用那些Java语言里面所不具有的特性,我认为他们最好是去使用JVM上的其他语言,譬如 Scala与Groovy。( Eastsun注:在 另一个访谈中Bloch提到他也很喜欢闭包,但是他认为当前流行的那些闭包提议过于复杂,会破坏Java语言的简洁性。事实上,他支持在Java中采用Bob Lee, Doug Lea,Josh Bloch三人所提出的 CICE方式;但Java之父Gosling则希望采用另一个更加彻底同时也更加复杂的实现方式: BGGA)

   Sugrue: To Java developers your book is seen as a bible. Can you recommend any other books to sit alongside yours on the developer's bookshelf?

   Bloch: Sure. For concurrency, I recommend Java Concurrency in Practice by Goetz, Peierls, et al. For bit twiddling, go with Hacker's Delight, by Henry S. Warren. A couple of classics that only improve with age are Frederic P. Brooks's The Mythical Man Month, and Jon Bentley's Programming Pearls. And every programmer should read Strunk and White's The Elements of Style. Not only will it make you a better writer (which is an important part of being a software engineer) but it will make you a better programmer. Programming and writing have a lot in common: both are about expressing yourself clearly and concisely.

你可能感兴趣的:(java,scala,Netbeans,groovy,java7)