程序員最可怕的噩夢是什么
What is a coder''s worst nightmare?譯文簡介
網(wǎng)友:我先來說說我的噩夢:一個心理學家雇我去修復(fù)一個程序,這個程序是他以前的一個研究生寫的,這個程序最后輸出來的結(jié)果有點奇怪。這是一個會讀取數(shù)據(jù)文件、能提出大約 50 個問題、并進行一些計算......
正文翻譯
What is a coder's worst nightmare?
程序員最可怕的噩夢是什么?
原創(chuàng)翻譯:龍騰網(wǎng) http://nxnpts.cn 轉(zhuǎn)載請注明出處
評論翻譯
很贊 ( 0 )
收藏
This was mine:
I was hired by a psychologist to fix a program that seemed to have "strange output" written by one of his ex-grad students. It was a program that reads a data file, asks about 50 questions, does some calculations, and comes up with some score based on this PhD's research. It's on a research 3B2 at the university. He demonstrates the program and sure enough there seemed to be strange flashing words on the screen when it moves from question to question, and they don't seem nice. I agree to do it, should be pretty straightforward, so he'll pay me by the hour to determine how big the fix is and then we'll agree to a fee.
我先來說說我的噩夢:
一個心理學家雇我去修復(fù)一個程序,這個程序是他以前的一個研究生寫的,這個程序最后輸出來的結(jié)果有點奇怪。這是一個會讀取數(shù)據(jù)文件、能提出大約 50 個問題、并進行一些計算,然后會根據(jù)這個博士的研究得出分數(shù)的程序。這是3B2的一項研究。他向我演示了這個程序,果然當它從一個問題移動到另一個問題的時候,屏幕上會閃爍一些奇怪的詞,而且這次詞看起來不太友好。最后我同意為他進行修復(fù),因為我覺得這個問題應(yīng)該很簡單。他說先按小時計費,然后再根據(jù)修復(fù)的大小,最后再跟我商定具體的費用。
I sit down at the 3B2 and login to the ex-grad student's account that has been given to me. This is where the code resides. I examine the C code. It is written to be hard to read. All the code is squished on one line. It's spread over 15 files with about 3 functions per file -- all on one line. All variable names are just three, seemingly random, letters. I talk to the guy and agree to go with hourly on this (great decision). I untangle all the code and format it nicely so I can see it.
It was done on purpose. It used the curses library to move to a point on the screen, print a question and the answers, and wait for a response. But it first went to the first line of the question, printed some white supremacy message, waited 1/2 a second, and then overwrote it with the question. This ought to be simple. There are only about five places it could output anything, and all of them had this subliminal flash of a message. dexe the offending mvprintw() and all is well. Or should be. I compile, thinking I'm done. But when I ran it, there it is again -- the subliminal messages. This time with different text still the same subject, just different messages.
I check my code and believe it or not it's back to the initial state I found it. 15 files, mangled, 3-letter variables -- the whole thing right back where I started. I want shoot myself for not making a copy of my code. I unmangle again, this time putting it in three files, named differently. I make a copy of the whole directory, and I mark the files readable only. I compiled it. All looks good. I run the program. There's now a copy of the original 15 files in the directory along with mine and the subliminal messages are back.
Okay, so somewhere on the disk is the source code necessary to keep doing this and he's set the program up to pull in that code when you compile it. I do a full disk search in the include areas (/usr/include) and since this is a research version we have source for just about everything but the kernel itself. That's a lot of header files and this takes some time on the 3B2, so that's day 1.
第1天:
我打開了3B2 ,然后登錄了他給我的以前研究生的帳戶。這就是代碼所在的位置。我檢查了 C 代碼,這個代碼寫得難以讀懂,所有的代碼都壓縮到了一行里。它分布在 15 個文件中,每個文件大約有 3 個函數(shù),而且這些函數(shù)還都在一行。所有的變量名都只是三個看起來很隨機的字母。然后我和那個心理學家談過了,同意在這個問題上按小時計費(這個決定做得非常好)。我解開了所有的代碼,并把他們?nèi)扛袷交?,這樣方便我查看。
這個程序是使用curses庫移動到屏幕上的某個點,再輸入問題和答案,然后等待響應(yīng)。但它是先到了問題的第一行,輸入了一些關(guān)于白人至上的不實信息,然后等了 1/2 秒之后,又用問題覆蓋了這個信息。當我發(fā)現(xiàn)這一點的時候,覺得這應(yīng)該挺簡單的,因為它可以輸出內(nèi)容的地方只有五個,而且這五個地方都有這種信息閃現(xiàn)。所以我刪掉有問題的 mvprintw()以后,一切正常,或者說應(yīng)該是一切正常,我以為我完成了修復(fù)。但是當我再運行它的時候,它又出現(xiàn)了那些不實的信息。這次雖然是不同的文字,但主題還是相同的,只是信息不同而已。
我又重新檢查了我的代碼,不管你信不信,這個程序又回到了它的初始狀態(tài)。 15 個損壞的文件,3 個字母的變量,一切又回到了我剛開始的地方。我當時特別后悔沒有把我的代碼復(fù)制過來,我只能把代碼再重新解開一次。我這次把它放在了三個文件中,并給它們編了不同的名字。我復(fù)制了整個目錄,并將文件標記為只讀。我開始修復(fù)這個程序,一切看起來都不錯?,F(xiàn)在在我的目錄里有15個原始文件的副本,然后我繼續(xù)運行程序,那些不當?shù)男畔⒂殖霈F(xiàn)了。
所以說,在這個磁盤上有一個地方有繼續(xù)執(zhí)行此操作的源代碼,并且他已經(jīng)將這個程序設(shè)置為在編譯時就引入該代碼。所以我不得不將這個程序所包含的區(qū)域全都進行了完整的磁盤搜索,因為這是一個研究版本,所以我們擁有除了內(nèi)核本身之外的所有源代碼。這是一個很大的母文件,所以需要在3B2上花費一些時間,但這才第一天。
The disk search showed up nothing. The strings were apparently either encrypted or they are buried in a library somewhere. I decide to search all libraries for the text. This is even longer than before, so day two is over.
Day 3
No results. The strings are encrypted. That means I'm going to have to follow all the header files from each #include and each one they #include to find where this is. And that will, take some time. We do alx the campus computing department that we believe someone has gained root level access to Dr. Phelps research computer, which is just a shared lab computer in the science building. They're understandably not convinced.
I start unwinding the #include files. I do that, nowhere do I find the code. So now I know it's compiled in a library.Why not just recompile all those libraries, we do have the source after all.
第 2 天:
我們在磁盤搜索中一無所獲。這些字符串要么是被加密了,要么是被藏在某個角落里。所以我決定搜索所有庫中的文本。這比第一天還要花費更多的時間,所以第二天就這么結(jié)束了。
第 3 天:
還是沒有結(jié)果。字符串被加密了,這意味著我將不得不跟蹤每個 #include 和每個 #include 中的所有母文件,來找到它的位置。這需要一些時間。我們提醒校園的計算機部門,我們認為有人獲取了菲爾普斯博士研究計算機的根級訪問權(quán)限,因為這個計算機只是科學樓里的一臺共享計算機。但是他們并不相信我說的話,但這也是可以理解的。
我開始跟蹤#include 文件。即使我這么做了,我還是找不到代碼。但現(xiàn)在我知道了它是在庫里編譯的。所以我們?yōu)槭裁床恢匦戮幾g這些庫呢,畢竟我們有源代碼。
The hardest part, convincing the campus nerds they have an issue. But we finally do and Mark, the Unix admin who was hired because he married the Dean's daughter, gets busy learning how to do this. In the end, he agrees to allow me to handle it, because he just doesn't really know how to get all that stuff compiled. End of Day 6, all standard libraries are recompiled. Woo hoo!
I whip out my modified, cleaned up source and start the compile. All looks good. I run it. O M G. It did it again. 15 messed up source files and the subliminal messages are back. This is suddenly like magic. I investigate very very carefully though I am stumped. This code doesn't exist in source code. I think I might be beaten. Dr. Phelps isn't happy with the hours involved and thinks maybe we ought to just rewrite the program from scratch. "Sure", I say staring at the terminal like a lost puppy too deep in my thoughts to put out of my thinking mode, "I think you're right. That will be quicker." "Good," he says, "we can start tomorrow."
Day 7
To hell with that. This guy isn't beating me. We are compiling it from his stinking code or not at all! "You don't have to pay me anymore, Dr. Phelps, I just want lab time." This is nerd war.
Days 8-14
I get smart, I'm thinking he somehow modified the curses library.I start learning. I read manuals for 6 days, piecing together that assembly code. Waste of time, nothing seems unusual.
第 4-6 天:
但最難的部分是,要如何說服校園里宅男們相信這個庫是有問題的。但我們最終還是做到了,因為馬克娶了院長的女兒,所以他被聘用為Unix的管理員,他一直在學習怎么編程。所以他最后同意讓我來處理這個問題了,因為他真的不知道如何編譯這些東西。等到第 6 天結(jié)束的時候,所有的標準庫都會被重新編譯。真是太棒了!
我拿出我修改過、清理過的源代碼并開始重新編譯,所有的進展都很順利。然后我又重新運行了一下程序。結(jié)果,我的天吶,又變成那樣了, 15 個混亂的源文件和不實的信息就像變魔術(shù)一樣又出現(xiàn)了。盡管我被難住了,但我還是非常仔細地繼續(xù)調(diào)查。源代碼中并不存在此代碼。我想這次的任務(wù)我可能要失敗了。菲爾普斯博士對我花了那么多時間還沒解決問題很不滿意,他覺得我們應(yīng)該從頭開始重新寫程序。我此時在這個問題中陷得很深,以至于無法擺脫我的思維模式,我像一只迷路的小狗一樣盯著終端機說, “當然,我認為你說的對,那樣做會更快?!彼f, “很好,那我們明天就可以重新開始了?!?br /> 第 7 天:
讓這個程序滾蛋吧,我不會被他打敗的。我們正在根據(jù)他這個惡心的代碼重新編寫程序,或者根本就不編了! “菲爾普斯博士,你不用再給我付錢了,我現(xiàn)在只想要在實驗室里繼續(xù)編程?!边@是兩個程序員之間的戰(zhàn)爭。
第 8-14 天:
我變聰明了,我覺得他是在以某種方式修改了這個程序的庫。我花了6天的時間去閱讀操作手冊,并把這些代碼拼在了一起。我在繼續(xù)消耗時間,這一切看起來并沒有什么不尋常的。
I suddenly realize it's in the compiler. It was the compiler. And every time you compile the original code and run it puts in the subliminal message code into the source code. I'd heard of this before.
Ah ah! I've got him!!!! We have the source code for the compiler as well. I search through it looking for a reference. Lo and behold, I find it. Indeed. There is source code in the compiler/lixer that does this:
1) it examines any call to fopen(), searches the file opened looking for Dr. Phelp's questions; if it finds them then
2) it rewrites the 15 files to the current directory when compiling that specific program.
3) It then compiles Dr. Phelps program using the 15 files and outputs to the -o name in the lix phase.
第 15 天:
我這天突然意識到它可能是在編譯器中。原來是編譯器!每次編譯并運行原始代碼時,它都會將不實的信息代碼放入源代碼中。我以前就聽說過這個。
我忽然想起我們也有編譯器的源代碼。我去找找看有沒有參考資料,果然,我找到了。確實,在編譯器或鏈接器中有執(zhí)行此操作的源代碼:
1.首先,它檢查了所有對 fopen() 的調(diào)用,如果發(fā)現(xiàn)有這些調(diào)用的話,它就會搜索打開的文件,來查找菲爾普斯博士的問題。
2.當你開始編寫該特定程序時,它就會將 15 個文件重新寫到了當前的目錄中。
3.然后用這15個文件編寫菲爾普斯博士的程序,并在鏈接階段輸出不好的言論。
Several days later, an AT&T tech shows up with a disk and loads the proper compile and lixer source and we recompile the compiler from the source. That solves it. All the bad source in the compiler is gone and we've got a new clean copy of the compiler.
that source code, that now existed only in the executable compiler, put those changes back into the compiler source before it compiled it. But this time it didn't modify the /usr/src copy, it copied it to a hidden directory, modified the compiler source, compiled itself from there, and dexed the hidden directory. It took an AT&T tech to find this. The ex-grad student had poisoned the compiler to poison itself when it was recompiled. We had to put a new binary version of the compiler on disk from another 3B2 running the same revision before the problem went away.
We also found that if /sbin/login is compiled it puts in a backdoor allowing anyone who uses a specific password to login in as the root user. This computer is accessible by modem and Tymnet. Finally, this gets the computing center's attention.
編譯器被修改為,將該代碼放入菲爾普斯博士的程序里。這個程序是由修改編譯器的人編寫的。
幾天后,AT&T 的技術(shù)人員帶著磁盤出現(xiàn)在我們的面前并加載了正確的編譯器和鏈接器的源代碼,我們從源代碼中重新編譯了編譯器。這樣問題就解決了,編譯器中所有的錯誤源代碼都消失了,我們得到了一個全新的編譯器副本。
那個源代碼,現(xiàn)在只存在于可執(zhí)行的編譯器中,在編譯之前將那些更改重新放回編譯器源代碼中。但這一次它并沒有修改/usr/src 副本,而是將其復(fù)制到一個隱藏目錄,修改了編譯器源代碼,從那里編譯,并刪除了隱藏目錄。 AT&T的技術(shù)人員找到了這個問題的來源。這位前研究生在編譯器重新編譯時毒害了編譯器。在這個問題解決之前,我們不得不把一個新的編譯器的二進制版本放在另一個相同版本的3b2的磁盤上。
我們還發(fā)現(xiàn),如果編譯了/sbin/login,它就會設(shè)置一個后門,允許任何使用特定密碼的人以 root 用戶身份登錄。這臺計算機可以通過調(diào)制解調(diào)器和 Tymnet 訪問。最后,這件事引起了計算中心的注意。
After an 11-hour work day I was greeted by my father and he announced he had promised his "future boss" that his son was going to program a "small" application for him. For free. But maybe the boss would "give a gift" to me after I complete it. His exact words.
This "small" application by any estimates would take me 1.5 months minimum, IF I didn't work 60 hours a week already. That one and a half months is an extremely conservative estimate since the guy handed him a post-it note with a 6-7 vague things as requirements.
I'm getting angry again so I'll get to the point instead of rambling on. The point is, a coder's nightmare is not made of code, bugs, programming languages, computers, tools etc. It's made of people. There's a reason coders become coders. I love computers, but man, fuck people.
當我工作了 11 個小時回到家后,我的父親在門口迎接我,并向我宣布,他已經(jīng)向他的“未來老板”承諾了,他的兒子將會為他免費編寫一個“小”的應(yīng)用程序。也許這個老板會在我完成這個程序之后,會送給我一份禮物。 這就是他的原話。
就算我每周工作 60個小時,這個“小”的應(yīng)用程序至少也要一個半月的時間才能完成。而且這一個半月還是一個非常保守的估計,因為那個老板給他遞了一張便利貼,上面寫著 6-7 條模糊的要求。
我真的是要生氣了,所以這次我要開門見山的跟我的父親說,而不是跟他東拉西扯。關(guān)鍵是,程序員的噩夢不是由代碼、錯誤、編程語言、計算機、工具等組成的,而是由人組成的。程序員之所以成為程序員是有原因的。我喜歡電腦,但是我真的不喜歡和人打交道。
Code works perfectly after the first try. I mean, what kind of sorcery is this? The stars are not even aligned today.
A call from a relative. I could be in a hospital and they’d still ask if I can fix the “Internet” for them.
Favorite coffee shop is closed. What am I supposed to drink? Water?
Clients from hell.
“Hey bro, I have this awesome idea that can change the world, you can code it for me, and I’ll even give you 30% of the company. No, really hear me out, it’s like Facebook, but instead of sending full text messages, only 140 characters. Isn’t this revolutionary?”
Clients who ask for changes that could take me days to implement, but want them at the end of the day.
“This is the computer genius I told you about. He can totally fix your printer that fell from the fourth floor.”
代碼在我第一次嘗試后就完美的運行了。 我的意思是,這是哪門子的魔法?。?今天的星星甚至都沒有對齊呢。
一個親戚給我打電話,問我能不能幫他們修好“網(wǎng)絡(luò)”。 就算我在醫(yī)院,他們還是會問我能不能幫他們修。
我最喜歡的咖啡店關(guān)門了。所以我應(yīng)該喝什么呢?喝水嗎?
我還有來自地獄的客戶。
“嘿,兄弟,我有一個可以改變世界的很棒的想法,你可以幫我寫代碼,我甚至可以給你公司30%的股份。 不,你聽我說完,它就像 Facebook一樣,但不是發(fā)送短信,它只有 140 個字符。 這難道不是革命性的變化嗎?”
客戶提的要求我可能要花好幾天的時間才能完成,但是他們想要我一天就能完成。
“這就是我跟你說過的那個計算機天才。 他甚至可以把你從四樓掉下去的打印機都能修好?!?/b>
I crashed the New York Times once.
Seriously.
See, I worked for a company that sold cars online, and we had the contract to do that on the New York Times' website, and one day we get a very angry call from them because their website is crashing and they've traced it to something on our side. We had a devil of a time tracking the cause of the crashes down, because it seemed to be happening at random. The web servers would crash, we'd restart them, they'd go all right for a bit, then slow down, and then crash again. It didn't happen after a set time period. It didn't happen when you did something specific. But it happened. Inevitably, it always happened.
After staying several hours late (you do not go home when you've got a live crash bug), I suddenly realized what was happening, and with a sinking sensation realized it was my fault. On one minor side page I'd made one minor assumption, and every experienced coder is going to slap their foreheads in frustration when they read it: I'd assumed the data would always be there.
It wasn't. The database had crashed. (So it was their fault too.) And my code was programmed to go and get the data and then not do anything else until it got the data. And there was no data to get. So the code was just sitting there, unable to complete, constantly asking the server for data that wasn't there. And since it wasn't there, it just sat there, asking over and over and over again with the monomaniacal tenacity .And since this particular piece of code ran when the associated widget loaded up on the sidebar of different pages on the newspaper's website, every time someone loaded a page, another instance of the code appeared on the server and started asking for its data. They'd just build up and build up and build up, not going away, until the server was first full of nothing except instances of the code bugging it for data, and then overfull and crashing as a result.
I rewrote the code so that it would check to see if there was data before it started to process the data, pushed that live in a hurry, we restarted the servers one more time, and the problem was fixed. And I have never trusted data since
我曾經(jīng)搞砸過《紐約時報》。
是非常嚴重地搞砸。
我在一家線上銷售汽車的公司工作,我們在《紐約時報》的網(wǎng)站上簽了合同,有一天我們接到他們的電話,他們很生氣,因為他們的網(wǎng)站崩潰了,他們追蹤到是我們這邊的某個東西導致的。因為這件事是隨機發(fā)生的,所以我們花了好長的時間才找到網(wǎng)站崩潰的原因。網(wǎng)絡(luò)服務(wù)器崩潰了,我們就會重新啟動它們,它們正常運行了一段時間,然后又變慢了,最后再次崩潰。它并不是在固定的時間段內(nèi)發(fā)生的。它不是因為你做了什么特別的事才發(fā)生的。但它還是發(fā)生了,這是不可避免地,只要你使用網(wǎng)絡(luò),就總是會發(fā)生這樣的事。
在回家晚了幾個小時之后(當你遇到一個崩潰的bug時,你就不能回家),我突然意識到發(fā)生了什么,并意識到這可能是我的錯,當我一想到這一點,我就感到非常沮喪。我在一個小頁面上,做了一個小小的程序,每個有經(jīng)驗的程序員在讀到這篇文章時,都會敲敲自己的頭:我以為數(shù)據(jù)會一直存在那里,但其實不是。所以數(shù)據(jù)庫崩潰了。(所以這也是他們的錯。)我寫的代碼是被設(shè)定去獲取數(shù)據(jù)的,所以它在獲取數(shù)據(jù)之前什么都不會做。因為沒有數(shù)據(jù)可以獲取,所以代碼只能停在那里,什么都做不了,只能不斷地向服務(wù)器請求不存在的數(shù)據(jù)。因為它不存在,所以它只是坐在那里,一遍又一遍地問,帶著一種偏執(zhí)的固執(zhí)。由于這段代碼是在《紐約時報》網(wǎng)站的側(cè)邊欄添加的,所以它只有在加載相關(guān)的小程序時才會運行,因此每當有一個人加載頁面時,服務(wù)器上就會出現(xiàn)另一個代碼并開始請求它的數(shù)據(jù)。他們只會不斷地積累,不斷地積累,但不會消失,直到服務(wù)器上除了這個錯誤的代碼什么都沒有,最后服務(wù)器就會因為超載而導致崩潰。
我重新寫了代碼,讓它在開始處理數(shù)據(jù)之前先檢查下是否有數(shù)據(jù),然后我就趕快將這個代碼發(fā)送了出去,我們再次重新啟動了服務(wù)器,問題得到了解決。從那以后我就再也不相信數(shù)據(jù)了。
Internal Politics
I have read quite a few answers here, but none of them touched this point. Consider this situation : you come up with an idea for small side project and you start working on it in your spare time. Now people start taking notice of this initiative and soon your manager assigns one more person to work on this with you.
When the project is completed, the idea is presented to the leadership. But wait, you didn't even know about this meeting. The meeting was set up by your manager and only those who are close to him are the ones who were invited to present the idea. You confront the others about why you were not included and your manager takes their side saying to think of the bigger picture and all the other bull shit that they say.
This happened with me exactly a week ago. This made me realize that this is not the place I want to work in. Hence started applying to various companies. Three days in, 2 job offers in my hand. Today before I sat down to write this answer, I handed in my resignation letter to my manager. One of the best decisions so far in my career.
還有公司里的內(nèi)部斗爭。
我在這里看到了很多答案,但沒有一個答案涉及到這一點。試想一下這種情況:你提出了一個小項目的想法,然后你就用你的業(yè)余時間來做它。有人注意到你的這個舉動,很快你的經(jīng)理就指派了一個人來和你一起做這件事。
當這個項目完成之后,你的這個想法就在會議上被提交給了上級領(lǐng)導。但是等等,你根本就不知道有這次會議。會議是由你的經(jīng)理安排的,只有那些與他關(guān)系密切的人才會被邀請來這個會議陳述這個想法。你質(zhì)問其他人為什么不把你加入這個項目里,你的經(jīng)理站在他們一邊,說要考慮大局,以及他們所說的一些廢話。
這件事就發(fā)生在一周前。這讓我意識到這不是我想要工作的地方。所以我就開始給不同的公司投簡歷。三天過去了,我現(xiàn)在手上有兩份工作邀請。今天,在我坐下來寫這個答案之前,我已經(jīng)把我的辭職信交給了我的經(jīng)理。這是我迄今為止的職業(yè)生涯中做的最好的決定之一。
Being in a project surrounded by non technical functional consultants or managers who think you are a wizard/genie/magician who can conjure up any code, learn any new programming language in 2 mins, build A+ level responsive UI even if you are a back end developer, do the work of 20 developers in a day and simply get all their fancy ideas to reality. In other words, stuck in a team which is bereft of the basic understanding of development and having highly unrealistic.
在一個沒有技術(shù)顧問或經(jīng)理的項目中,他們認為你是一個可以召喚出任何代碼的巫師、精靈、或魔術(shù)師,他們認為你可以在 2 分鐘之內(nèi)學會一門新的編程語言,即使你是后端的開發(fā)人員,你也能構(gòu)建 A+ 級別的響應(yīng)式 UI ,你能在一天內(nèi)完成 20 個開發(fā)人員的工作,并將他們所有的幻想變成現(xiàn)實。換句話說,他們被困在一個對開發(fā)缺乏基本理解的思維中,并且對他們唯一的開發(fā)人員有著非常不切實際的期望。
原創(chuàng)翻譯:龍騰網(wǎng) http://nxnpts.cn 轉(zhuǎn)載請注明出處
This is not my nightmare, but something that happened to me in real life. When you read this, it will become YOUR nightmare from now on!
The situation:
I'm a senior software developer working at a large software company,
We write in PHP and use Zend IDE 4.0,
The Ctrl key on my keyboard is kind of broken, sometimes it doesn't respond when pressed,
I'm working on a large enterprise web application for a government project with an approaching deadline.
I got to work in the morning, turned on my computer and started working on a PHP file. I wrote thousands of lines of code, solved many unsolvable problems, and fixed many hard bugs. I had a super productive day. At the end of the day, I asked my boss and my project manager to see the result of my work. I, overflowed by Serotonin resulted from a good work day, presented everything on my computer while they were standing behind me and they got happy.
這不是我的噩夢,而是在現(xiàn)實生活中發(fā)生在我身上的事情。當你讀到這篇文章的時候,它將會成為您的噩夢!
這件事的情況是:
我是一家大型軟件公司的高級軟件開發(fā)人員,
我們是用 PHP 編寫程序并使用 Zend IDE 4.0,
我鍵盤上的 Ctrl 鍵壞了,有時按下它沒有反應(yīng),
我正在為一個政府項目開發(fā)一個大型的企業(yè)網(wǎng)絡(luò)應(yīng)用程序,時間緊迫。
我從早上就開始工作了,我打開我的電腦并開始處理一個 PHP 文件。我編寫了數(shù)千行代碼,解決了許多無法解決的問題,并修復(fù)了許多棘手的bug。我度過了非常充實高效的一天。在一天結(jié)束的時候,我讓我的老板和我的項目經(jīng)理看到了我的工作成果。當他們站在我的身后時,看到我電腦上所展示的東西,他們很高興。
I tried to press Ctrl+S to save the file. But I mistakenly pressed Ctrl+A (sext all) instead. The whole text of my file got sexted.
Once again I tried to press Ctrl+S. But since my Ctrl was semi-broken, this time I didn't press it hard enough and it didn't work. So, my whole thousands of lines of code got erased and got replaced by a single "s".
I panicked. I pressed Ctrl+S once again, and this time it worked, and saved the new file contents (a single byte "s").
These all happened in 3 seconds. I tried to use Ctrl+Z to undo the last change. But as you may know, in early versions of Zend IDE, the undo function was implemented very badly. So it got me to the morning, when I started my work on the file.
There was no backup or SCM revision. I lost everything. I just wanted to cry, and cry, and cry... The good thing was that my boss and the project manager saw the completed work and witnessed the procedure of destroying my own work. I stood there for a few minutes shocked, and then I left work sad and depressed.
Needless to say, I got a new keyboard the next day! But I learned my lesson for life. Nowadays I always backup my work. I install Ditto (a very good open source clipboard manager program for Windows) and periodically "Ctrl+A, Ctrl+C" (copy all) my work into the clipboard just in case. I always use source control software (Git) and commit regularly.
他們給了我一個”干得漂亮”的表情后,我決定最后再保存一次文件,我將提交到我們的 Visual SourceSafe 服務(wù)器上,然后就關(guān)閉了工作。這些事都發(fā)生在 3 秒之內(nèi):
我嘗試按 Ctrl+S 保存文件。但我錯誤地按下了 Ctrl+A(全選)。我文件的整個文本都被選中了。
我再次嘗試按 Ctrl+S。但是由于我的 Ctrl 是半壞的,而這一次我又沒有用力按下它,所以它沒起任何作用。所以,我的數(shù)千行代碼都被刪除了,并被一個“s”取代了。
我驚慌失措。我再次按下 Ctrl+S,這次它起作用了,并保存了新的文件內(nèi)容(一個字節(jié)“s”)。
這一切都發(fā)生在 3 秒之內(nèi)。我嘗試使用 Ctrl+Z 撤消上次更改。但是您可能知道,在 Zend IDE 的早期版本中,撤消功能非常糟糕。所以它讓我到了第二天早上,還在處理那份文件。
由于我沒有備份或留存 SCM 的修訂版。所以我失去了一切。我只想哭,不停的哭,但好在我的老板和項目經(jīng)理看到我完成了工作,并見證了我銷毀我自己工作成果的過程。我當時震驚地呆在原地幾分鐘,然后又沮喪地離開了我的工作崗位。
不用說,我第二天就得到了一個新的鍵盤!但我這次吸取了人生的教訓?,F(xiàn)在我經(jīng)常備份我的工作。我安裝了一個 Ditto(一個非常好的 Windows 開源剪貼板管理器程序)并定期“Ctrl+A、Ctrl+C”(復(fù)制所有的東西)我的工作到剪貼板里,以防萬一。我一直在使用源代碼管理軟件 (Git) 并定期提交。
It was an unfortunate accident. It could happened even to Bill Gates, Steve Jobs, Linus Torvalds, Mark Zackerburg, etc. Even with the best keyboards, IDEs, source control software, etc. I mean if it's going to happen, then it's going to happen.
This story belongs to 8-10 years ago. So no Git or Dropbox or advanced IDEs with features like auto backup, revisions, commits, etc. We even haven't had a stable internet connection inside the company. My monitor as a senior software developer was a 17" CRT monitor for God's sake!
Zend IDE was the official IDE for the company. Visual SourceSafe was the official source control and Windows was the official OS. While personally I prefer using Eclipse (and Git and FreeBSD/Linux), I had no other choice than following the rules. Fortunately Zend IDE 5.0 was based on Eclipse.
Replacing the keyboard is hard for me. I think more professional programmers understand me. Even a slight change in the keys placement, size, smoothness, ... can highly reduce your typing performance and increase your use of backspace. So when my keyboard gets broken, I need to spend a lot of time to look for a good replacement.
It's true that keyboards has two Ctrl keys and I could also use the Edit menu. But when you get used some patterns, you would use them without thinking. Also to press Ctrl+S, you use the nearest and easiest Ctrl key to S, in this case the left Ctrl. I don't think anybody use the right Ctrl or the Edit menu ever!
The file I was working on that day was part of a huge proprietary PHP frxwork. The frxwork structure dictated how the files should be arranged. From time to time, we had no other way than putting thousands of lines of code in a single file.
I'm a programmer for 20 years. I don't say that I'm too professional. But I probably have enough experience to know what I'm doing and is this a correct way to do something or not. This was an "accident".
編輯:有一些讀者提出了一些建議來防止再次出現(xiàn)這個問題,例如使用Git,選擇使用更好的IDE,更換我的鍵盤等等。他們還說我既無知又不專業(yè)。所以這是我的回答:
這是一次不幸的事故。它甚至可能會發(fā)生在比爾·蓋茨、史蒂夫·喬布斯、萊納斯·托瓦茲、馬克·扎克伯格他們身上。即使是有最好的鍵盤、IDE、源代碼控制軟件等,都有可能會出現(xiàn)這種意外。我的意思是,命中注定要發(fā)生的事,就一定會發(fā)生。
這個故事發(fā)生在8-10年前。所以沒有 Git 或 Dropbox 或具有自動備份、修訂、提交等功能的高級 IDE。我們公司內(nèi)部甚至還沒有穩(wěn)定的網(wǎng)絡(luò)連接。作為一個高級軟件的開發(fā)者,我的顯示器竟然還是17英寸的CRT顯示器!
Zend IDE 是該公司的官方 IDE。 Visual SourceSafe 是官方的源代碼控制,Windows 是官方的操作系統(tǒng)。雖然我個人更喜歡使用 Eclipse(以及 Git 和 FreeBSD/Linux),但除了遵守規(guī)則之外,我別無選擇。幸運的是 Zend IDE 5.0 是基于 Eclipse的。
換鍵盤對我來說很難。我想只有專業(yè)的程序員能理解我。即使在按鍵的位置、大小、平滑度等方面有一點點的變化,都會大大降低您的打字速度,并提高了退格鍵的使用頻率。所以當我的鍵盤壞了,我需要花很多的時間去尋找一個好的替代品。
確實,鍵盤有兩個 Ctrl 鍵,我也可以使用“Edit”菜單。但是當您使用某些鍵,使用習慣了以后,您就會不假思索地使用它們。同樣要按 Ctrl+S,您可以使用與 S 最接近且最簡單的 Ctrl 鍵,在本例中為左側(cè) Ctrl按鍵。我認為從來沒有人使用過正確的 Ctrl 或Edit菜單!
我那天正在工作的文件是一個巨大的PHP 框架的一部分??蚣芙Y(jié)構(gòu)決定了文件的排列方式。有時,我們只能將數(shù)千行代碼放在一個文件中。
我做了20年的程序員。我并不是說我自己非常專業(yè),而是我有足夠的經(jīng)驗,知道我在做什么,以及這么做對不對。所以這件事的發(fā)生就是一個“意外”。