David Thomas:程序員要快樂的思考
原創(chuàng)【51CTO獨(dú)家特稿】一個(gè)國(guó)外的技術(shù)大牛,一開始其實(shí)只是為了解決具體的技術(shù)問題而鉆研技術(shù)。但是經(jīng)歷了一段時(shí)間的鉆研,程序員就有可能從中體會(huì)到樂趣,真正做到快樂的寫代碼,快樂的思考。David Thomas就是這樣一位快樂的程序員。
人物簡(jiǎn)介
Dave Thomas,敏捷宣言創(chuàng)始人之一,《程序員修煉之道》與《Programming Ruby》的作者。他有著三十余年的編程經(jīng)驗(yàn),現(xiàn)在主要經(jīng)營(yíng)Pragmatic Programmer出版社,閱書無數(shù)。同時(shí),Dave每天都仍然在編寫代碼。
1、你最開始從事開發(fā)的時(shí)候,有什么技術(shù)理想么?這個(gè)技術(shù)理想在之后的年歲中有過改變么?
我最開始編程的時(shí)候,我認(rèn)為那時(shí)的自己還談不上有什么技術(shù)理想——這是很久之后才有的。
我在16歲的時(shí)候,準(zhǔn)備在高中學(xué)習(xí)數(shù)學(xué)。我當(dāng)時(shí)還在英國(guó)念初中,我們一群孩子提前一年完成了學(xué)業(yè)。學(xué)校想找點(diǎn)事情給我們做,就建議我們?nèi)ヒ粋€(gè)本地的技術(shù)學(xué)校(類似中專)上一門計(jì)算機(jī)編程的課程。在那個(gè)時(shí)候,你通過300波特調(diào)制解調(diào)器、電傳打字機(jī)和紙帶機(jī)和計(jì)算機(jī)進(jìn)行交互。在這門課上了一個(gè)月左右的時(shí)候,我忽然發(fā)現(xiàn)了我真正喜愛的東西。每天下課之后,我用好幾個(gè)小時(shí)在紙帶上編寫B(tài)asic程序,再上傳到大型主機(jī)上。我甚至進(jìn)行了我的第一次元編程——由于我們被限制只能在主機(jī)上保存5個(gè)程序,我于是編寫了一個(gè)可以儲(chǔ)存其他程序的Basic程序,就好象一個(gè)迷你的文件系統(tǒng)。
經(jīng)歷過這些之后,我意識(shí)到了我對(duì)編程的渴望。我在接下來的大學(xué)選科過程中沒有再看任何的數(shù)學(xué)課,而是搜索有沒有計(jì)算機(jī)科學(xué)的課程。幸運(yùn)的是,帝國(guó)理工學(xué)院剛剛開辦了一門計(jì)算機(jī)科學(xué)的課程,我就這么進(jìn)去了。這門課程可能是這個(gè)領(lǐng)域最好的入門指導(dǎo)了:課程本身相當(dāng)深入,課外練習(xí)都十分實(shí)用,而且十分具有挑戰(zhàn)性?;旧?,我在學(xué)校期間靠編程打工的錢就把我的學(xué)費(fèi)全付清了。
畢業(yè)之后我計(jì)劃讀博士,不過一個(gè)初創(chuàng)企業(yè)把我拐走了。我覺得這其實(shí)是挺幸運(yùn)的,因?yàn)榻柚@次創(chuàng)業(yè)的機(jī)會(huì),我認(rèn)識(shí)到了軟件業(yè)務(wù)的另一面:客戶,項(xiàng)目,以及正確的做事。公司很小,但都是非常聰明的人,所以只要是能找到的活兒,我們什么都做。在短短數(shù)年間,我在各個(gè)方面積累了大量的經(jīng)驗(yàn)。
所有這一切都是由熱情推動(dòng)的,而談不上什么技術(shù)理想。我只是做我喜歡做的事情。
不過,久而久之,我開始意識(shí)到工作中的“模式”(patterns)——在軟件開發(fā)工藝的深層隱藏的那些真理。最終,我和Andy Hunt將其中的一些模式描述成文字,記錄在我們的《程序員修煉之道》當(dāng)中。
不過,這仍然算不上什么“技術(shù)理想”。你這個(gè)問題很好,它引發(fā)了我的思考。思考的結(jié)果就是,如果“技術(shù)理想”的含義是“我想要做這個(gè)或那個(gè)”,那么我并沒有任何技術(shù)理想。我的理想很簡(jiǎn)單:做我高興做的事。我想要繼續(xù)寫代碼,我想要用代碼解決人們的問題。我想要繼續(xù)磨練我的手藝,我想要在軟件開發(fā)的新領(lǐng)域中測(cè)試和體驗(yàn)。我知道這有點(diǎn)自私,不過我想要繼續(xù)“尋歡作樂”:)
2、你有沒有感到某個(gè)時(shí)刻,你忽然“頓悟”了編程?如果有的話,能描述一下當(dāng)時(shí)發(fā)生的事情嗎?
當(dāng)然有過忽然靈光一現(xiàn)的時(shí)候。有些時(shí)候,只是比較低層次的。我還記得當(dāng)我在PDP-11計(jì)算機(jī)上編程的時(shí)候,遇到了一個(gè)將二進(jìn)制數(shù)字轉(zhuǎn)化為八進(jìn)制ASCII碼的庫(kù)子程序。很明顯,這是任何一個(gè)程序員都能夠?qū)懗鰜淼墓δ?。不過,我遇到的這個(gè)程序被編寫的十分“優(yōu)雅”:這位程序員使用了PDP標(biāo)志寄存器(flag registers)和旋轉(zhuǎn)運(yùn)算(rotate operations)的一些深層知識(shí),用短短四、五行匯編就完成了這個(gè)功能。這并非是我印象中最短小的代碼,但我當(dāng)時(shí)領(lǐng)悟到了:想要變得優(yōu)雅,必須深入理解你編程的環(huán)境。大多數(shù)開發(fā)者只是對(duì)他們使用的工具有一個(gè)表層的理解,所以他們生產(chǎn)的代碼四平八穩(wěn)。只有那些愿意花費(fèi)時(shí)間深入學(xué)習(xí),去了解底層都在做什么的開發(fā)者們,才能生產(chǎn)出優(yōu)雅的、革命性的代碼。
此外,也有一些技術(shù)之外的“頓悟”。在我職業(yè)生涯的早期,我有一次和我們創(chuàng)業(yè)的老大一起去見一個(gè)客戶。這位客戶是一個(gè)很大的軟件公司的擁有人,是我們這個(gè)產(chǎn)業(yè)中一個(gè)重要的人物——更重要的是,他手上有我們需要的項(xiàng)目。在商談的過程中,我發(fā)現(xiàn)客戶想要我們做的東西根本做不成,因?yàn)樗┑袅艘恍┘夹g(shù)問題。當(dāng)時(shí)的我很傻很天真,就直接跟他說這個(gè)不行。一時(shí)之間,屋子里陷入寂靜,而這次商談也很快結(jié)束了?;氐睫k公室,我想,我肯定要被炒魷魚了,因?yàn)槲翼斪擦丝蛻?。不過沒想到的是,我的老板教了我一件事,這使我終身受益。老板說,我道出事實(shí)這件事沒有錯(cuò)。如果我們發(fā)現(xiàn)有一個(gè)問題將會(huì)導(dǎo)致項(xiàng)目無法進(jìn)行,那么如果我們?nèi)匀唤酉逻@個(gè)項(xiàng)目,就是沒有職業(yè)道德。不過,問題在于我提出意見的方式:如果一個(gè)人的想法有錯(cuò)誤,不要直接跟他說“這是錯(cuò)的”。你應(yīng)該做的是想辦法引導(dǎo)他自己發(fā)現(xiàn)問題所在。
其實(shí)這些事請(qǐng)我現(xiàn)在仍然不是特別擅長(zhǎng)。我仍然會(huì)因?yàn)轫?xiàng)目的技術(shù)挑戰(zhàn)而撓頭,也經(jīng)常會(huì)忘記了人的因素。不過,那些“頓悟”的瞬間的確存在。
3、你的編程生涯中,最令你印象深刻的事情是什么?如果你能夠給那時(shí)的自己提供一些建議,你會(huì)說些什么?
在西方,我們有這樣一條諺語(yǔ):“祝你生活在有趣的時(shí)代(May you live in interesting times)”(譯注:據(jù)傳這是一句古老的中國(guó)詛咒,由一位英國(guó)駐中國(guó)的外交官傳回西方,后變成西方的祝詞。中文原文已不可考,有說法是“寧為太平犬,不做亂世人”)。這是一條溫柔的詛咒,因?yàn)橛腥さ臅r(shí)代同時(shí)也意味著艱難的時(shí)代。我覺得我們現(xiàn)在正生活在這條詛咒當(dāng)中。沒有任何一個(gè)時(shí)代比我們現(xiàn)在所處的時(shí)代更加有趣,同時(shí)也更加令人混亂。新的技術(shù),新的技巧,新的語(yǔ)言,新的期待。所以我最大的希望是,我編程生涯中最美好的事情還沒有到來。我希望最令我印象深刻的事情發(fā)生在未來。我的工作,我的熱情,都在盡可能的經(jīng)歷更多的事情,所以最令我印象深刻的事情一定會(huì)發(fā)生在未來。
以下為51CTO采訪英文原文
1. Aspiration
When you first started programming, what was your technical aspiration? Has your aspiration changed over the years?
I don't think I had a technical aspiration when I first started programming—that kind of thing came a lot later.
When I was 16, I was planning to study mathematics at college. I was still in secondary school in England, and a group of us had finished all our required classes a year early. The school was looking for things for us to do, and suggested we might be interested in attended a class on computer programming at the local technical college (a vocational school). This was back when you interacted with computers using 300 baud modems, teletypes, and paper tape. And sometime during the first month of that class, I realized that I'd found something I truly loved. I spent hours after school slowly typing Basic programs on to paper tape before uploading them to a mainframe. I even did my first metaprogramming—we were only allowed to store 5 programs up on the mainframe, so I wrote a Basic program that stored my other Basic programs inside itself, a kind of mini filesystem.
After that experience, I knew I wanted to write code. I stopped looking at university mathematics courses and instead looked for computer science. And I was lucky—Imperial College in London had just started a course, and I got in. It really was the best possible introduction to the field—the course itself was deep, and the work outside the course was practical and challenging. I ended up paying my way through school with programming jobs.
After I graduated, I started working on a PhD, but got tempted away by a start-up. I think this was also a very lucky move, because I suddenly learned the other side of the software business—clients, projects, and doing things right. The company was very small and full of very smart people, so we'd do just about any work we could find. I got an incredible amount of experience in a very broad range of topics in just a few years.
All of this was driven by a passion, not by any kind of technical aspiration. I was just doing what I enjoyed doing.
But, over time,I also started to realize that there were patterns in the work—underlying realities in the craft of developing software. Eventually, Andy Hunt and I captured some of these in our book The Pragmatic Programmer.
But I still don't think these count as "technical aspirations." You question was a good one, and it made me think. In the end, I don't think I have a technical aspiration, if the phrase means "I hope I do this or that technical thing." Instead, my aspiration is simple—I want to continue to do what I enjoy doing. I want to continue to write code, and to solve people's problems using code. I want to continue to improve at my craft, and to experiment with and experience new areas of software development. I know it's selfish, but I want to continue to have fun!
2. Insight
Have you ever experienced the change from "have no insight" to "have insight" in programming? Has there been a day on which you suddenly realised "oh, this IS the right way to programming"? If so, can you describe what grabbed you on that day?
I have definitely had those moments where suddenly something snaps into place. Sometimes these are really low-level technical moments. I remember when I was programming PDP-11 computers, I came across a library subroutine that converted a binary number into its ASCII octal representation. Of course, this would have been a function that any programmer could write. But this particular developer had done it *elegantly*, using a deep knowledge of the PDP's various flag registers and rotate operations to do the whole thing in just four or five lines of assembler. It wasn't the small size of the code that I remember—the insight was that you had to really understand the environment you were using if you wanted to be elegant. Most people have a surface understanding of the tools they use, and they produce solid, average code as a result. But the people who spend the time to dig deep, and to learn what's really going on—those are the people who produce elegant and revolutionary answers.
I also experienced nontechnical insights. I remember early on in my career I was at a client meeting with the owner of the startup I worked for. The client was the owner of a large software company; an important person in our industry, and, more importantly, someone with a project that we really needed :) During the meeting, it became clear that what he wanted us to write wouldn't work—he'd overlooked some technical problems. Being very young and very naive, I told him this. The room went silent, and the meeting ended very quickly after that. On our way back to our office, I expected to get fired for disagreeing with a client. But, instead, my boss taught me a lesson that I still use. He said that I was right to speak up. He said that if there was a problem that would stop the project working, we'd be unethical if we went ahead. But then he said that I was wrong to speak up the way I did—if there's a problem with a someone's ideas, don't just say "that's wrong." Instead, try to guide them to find the problem for themselves.
I'm not very good at this—I still get caught up in the technical challenges of projects, and I too often forget the human side, But the lesson—the insight—is still valid.
3. Back to the past
What is the most memorable thing in your programming career? If you can give suggestions to yourself at that time, what would you say?
In the West, we're told that there is a saying: "May you live in interesting times." it's meant as a mild curse—interesting times are difficult times. And I think we're all living with that curse right now. Times have never been more interesting, or more confusing. New technologies, new techniques, new languages, and new expectations surround us. So I very much hope that the best part of my programming career has not yet happened. I hope that the most memorable thing I'll do lies in the future. My job, my passion, is to experience as much as I can so that I maximize the chances that this will happen.
【編輯推薦】






