Interview with Google's chief Java Architect: choosing a programming language is like choosing a bar

Source: Internet
Author: User
Translated by Peter Seibel/Hao peiqiang

This article is an interview with Joshua Bloch, Chief Java architect of Google, by Peter Seibel, expert of commmon lisp, talking about what books programmers should read, how they can quickly get familiar with a new language, and why they choose programming languages is like choosing a bar.

  

  Seibel: How did you start programming?

Bloch: I think this is because of my family influence. My father is a chemist at the Brookhaven National Laboratory. When I was in grade 4, he attended a program design training class. Of course, at that time, computers were all placed behind the windows, and you had to hand over the program cards to the operator. Although I can't do it myself, I was shocked by the fact that e-computers can help you do things. So I learned a little Fortran from my father during his class.

  Seibel: Which year is it?

Bloch: I think it's July 1971. It wasn't until many years that I really had a strong interest in the program. Of course, what interests me is the time-sharing system. Long Island has a DEC system-10 computer for all schools in Suffolk County. There is also one in Nassau County. What's amazing is that the careers of many famous people started with the two dec system-10 computers.

Once your program interacts, there will be bugs. Probably from 1973 ~ In 1976, I was writing basic programs like other people. I started to write the program from that time. You know, I still keep the program I wrote in that year, which was printed on the telecommunications printing paper. Now, when I look back at these programs, I find that some parts of my code style have never changed since that time.

  Seibel: Do you still remember the first interesting program you wrote?

Bloch: Oh, I remember that it was in July 4, 1977. I wrote a program for the classic question 20 game called "Guess animal ". This program contains a binary tree, which is not a question on its internal node, and an animal on its leaf node. If the animal mentioned by the user is not on the leaf node, it will ask the user non-question, by distinguishing the difference between the new animal and the wrong animal it guessed to understand the new animal. The binary tree is stored on the hard disk, so that the program can be "smarter ".

I thought, "Oh, it's really cool. The program can really learn ." This is an unforgettable moment in my life. I still remember another thing. At that time, I was in high school. It should be grade 10. It is about Dec system-10. At that time, we were not allowed to write what is now called the instant messaging software, because they consume too much system resources.

  Seibel: If time goes backwards, everything can start from scratch. What do you really want to change? Is Basic too simple for you? What else is there?

Bloch: I have no regrets. In fact, basic is very interesting. I think Dijkstra's opinion on basic is totally wrong. Forgive me for saying this to the late man. May he rest in heaven. I know many very good programmers who started from basic programming, because that is the only language they can find.

However, I think using multiple languages is a good thing. When I went to college, I used many programming languages. Each course can use one language. FORTRAN should be used in mathematics or science and engineering classes. At that time, programming classes were all about pascal, sail, Simula, or something similar. In the AI class, lisp is used.

But maybe I should learn more languages. Interestingly, at the beginning, I didn't catch a cold eye on Object-Oriented games. It wasn't until the game development in question 20 was almost over. I really felt like object-oriented. Strictly speaking, Java is the first object-oriented language I actually use. To some extent, it is because I don't really want to use C ++.

  Seibel: when is that?

Bloch: That was when I joined sun in 1996. I think it would be nice if I could learn these concepts earlier. I don't think these concepts are good. Object-oriented has two meanings. First, it means modularization. Modularity is very good. But I don't think this is a patent for people who create object-oriented. You can go to the previous documents, for example, parnas's discussion about information hiding, and you will find that this concept can be seen as an abstract prototype of class concepts in object-oriented programming. Second, it means inheritance. I think inheritance has both advantages and disadvantages, which is consistent with the usage experience of many people today.

In addition, I should enter more fields, both inside and outside the computer science field. The more things you learn, the sooner you start, the better for you. What I have never done is GUI programming. To some extent, I should force myself to do it. However, for various reasons, such as developing library code and building code blocks that can be used by others over the years, these tasks have taken most of my time. In this way, I have been working on data structures and algorithms for decades.

  Seibel: What books should all programmers look?

Bloch: design patterns is undoubtedly a book. Although my feelings for it are a bit complicated, I still think everyone should read it. The book lists general terms and offers many good ideas. On the other hand, this book is a bit like a hodgedge of methods and languages, and the content is outdated. But I think it is definitely worth reading.

Another book is elements of style, which is not even a programming book. Why should I read this book? There are two reasons. First, a large part of each software engineer's work is to write documents. If you cannot write accurate, unified, and easy-to-read instructions, no one will use your product. Therefore, things that can improve your writing style are worth learning. Secondly, most of the ideas in this book apply to programming.

My desert island list is a bit odd. For example, the most important book is Hacker's delight, written by Herry Warren ).

  Seibel: Is this a bit-twiddling book?

B Loch: Yes. I love bit operations, which are associated with my work. This book is indispensable if you write libraries, compilers, underlying graphic code, or encryption code. Warren put the word of mouth together and used rigorous mathematics for verification. I was shocked when this book was published.

Of course, there is also the art of computer programming by knuth. In fact, I have never read this set of books, at least not from start to end. But when I study a specific algorithm, I will see what it will say. I often get what I want. This set of books is too comprehensive.

But I have no ability or time to read the complete set of books, so if I tell you that I have finished reading, then I am lying. I think there is another very good old book, the elements of programming style written by kernighan and plauger. The examples in the book are written in fortran iv and PL/I, so they are somewhat outdated. However, although this book is so old, its ideas are never outdated.

Another old book is Frederick Brooks's mythical man-month. This book has been published for 40 years, and its thoughts are still as influential as they were at the press time. Reading it is a pleasure. Everyone should read it. The main information in this book is "adding a person to an extended project will make it more postponed". Today this is still true. There are many other important points. Although some details are outdated, they are still worth reading.

Now everyone must learn concurrent programming. So you should read this book "Java concurrent programming practices. Although the title contains Java, many contents are not limited to any specific programming language.

  Seibel: This is the book you co-authored with Brian Goetz?

Bloch: My name is printed on the cover, but I mentioned it because it is not my book. The first author is Brian and the second author is Tim Peierls, and everyone who develops the Java concurrency standard JSR-166 is the author of this book. I printed my name on the cover just out of courtesy. I contributed some materials but did not formally write this book.

Oh, there is another one: the Wei's College Dictionary (version 11th). I carry it wherever I go. This is not what you actually want to read, but I have said that when writing a program, you must be able to name variables. Your document must be good. Without a good dictionary, I will feel something missing.

  Seibel: Apart from naming variables and copying and pasting as few as possible, which write programs have changed after your experience?

Bloch: As I grow older, I gradually realize that programming is not just about making programs run. Programming is about creating an easy-to-understand, maintainable, and efficient file. In general, I found that clean and tidy code often runs faster. This is the opposite of popular ideas. And even if they are not fast, they can be easily made faster. As people have said, it is much easier to optimize the correct code than to correct the optimized code.

Some of my changes are related to specific languages. Each language provides a toolbox. You must use the correct tool. The correct tool in this language may not be the best in another language. For example, if you use Java 5 to replace Integer constants or Boolean constants with enumeration, You can greatly simplify the program and make it safer and more reliable.

  Seibel: Can you talk about how to quickly get familiar with a new language?

Bloch: This is similar to the human language. One way is to learn many languages. If you are familiar with Italian and Spanish, it will not take much time to learn Portuguese. The more you know, the more you can absorb.

When learning a new language, you must use the skills of the language you have learned before, but you must keep an open mind. Some people stick to the idea: "This is the way to write all programs must follow ." I don't know which language it is, but some languages, for some reason, are obsessed with this idea. When they begin to learn new languages, they criticize the differences between these languages and the real language of God. When they use a new language, they try to use the real language of God to write. In this way, you will miss the true uniqueness of the new language.

This is like you have only one screw head. Someone gave you a screw driver and you said, "Alas, this is not a good one, but I should be able to hold it upside down, use a screw driver to smash things." You get a very bad rolling head, but in fact it is a very good screwdriver. Therefore, you should be open and positive to everything. Of course, the most important thing is the code! Code! Code! You must use multiple languages to learn more quickly.

  Seibel: why are people so devout about the selected computer language?

Bloch: I don't know. However, when choosing a language, you should not only consider a series of technical trade-offs, but also select a community. This is like choosing a bar. Yes, you want to go to a bar that provides wine, but wine is not the most important thing. This is mainly about people in the bar and what they are talking about. This is also true if you select a computer language. For a long time, this language has also formed a community where there are not only groups, but also their software achievements, such as tools and libraries. This is why theoretically better languages cannot succeed, and they cannot build successful communities around them.

  Seibel: if you understand this, Java is very interesting. It has two communities. One is the implementer and system developer, that is, people who work in the same oft, WebLogic, or similar places. The other is for all people who use Java, application servers, and constructed frameworks to build commercial applications. The two bars are very different.

Bloch: There are many communities associated with Java or other languages. If there is no Community around the language, it usually indicates that either the language is not well-known or immature. The language boom naturally shows more and more communities. At the same time, if the total investment in a language increases, its value will also increase accordingly.

This is like Metcalfe's law (Editor's note: a law of network technology development, proposed by Robert metcala, founder of 3com and pioneer in computer networks .) : The value of the network is directly proportional to the number of users. This is also applicable to programming languages. All users using this language form a community, and then suddenly eclipse, findbugs, and guice appear. Even if Java is not the best language for you, using it has so many additional benefits, you will still create a community to solve the problem of mathematical programming in Java, or other programming methods you need.

  Seibel?

Bloch: Of course. This is also true for writing books. Every time I start one thing, I always want to escape it. It was the most difficult at first, and sometimes I encouraged myself: "Come on, Josh! You have been doing this for more than 30 years. You know how to do it as well as others. You don't have to worry about it ." You can also say to yourself, "You see, you have done a good job in the past, and this time you cannot make a mistake ."

 Seibel: You mentioned that your life experience has become wider, which may affect programming. But is there anything other than programming, but have you become a better programmer?

Bloch: Of course. I think everything you can do has this effect. There is no discipline restriction on the idea. I came up with an example. When I write a thesis, I want to analyze a distributed data structure, RSM (replicated sparse memory, replicated sparse memory. The basic idea of this analysis comes from the Chemistry Course I attended. It is a dynamic equilibrium formula: if there is a dynamic equilibrium relationship in the system, you can write an equation, "the speed at which a thing enters a specific State is equal to the speed at which they leave this state." In this way, we get three equations of three variables, solve these three equations, and the calculated results exactly match the observed behavior of this complex distributed data structure. This is the idea that I directly steal from chemistry for computer science.

Many of the things you see in your life can be borrowed, regardless of the architecture, the building method, or the language, that is, the way people communicate. Of course, it includes mathematics. Mathematics and programming are quite similar. Therefore, you must open your eyes and actively absorb and reorganize various ideas.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.