給程序員的錯誤找個臺階

{"type":"doc","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"blockquote","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"2020這個人生最漫長的寒假,翻了一些書,記下不少名人趣事。百無聊賴間把這些小故事做了個分類,再把平日所見種種對照落入其中,遂成此短文。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"我工作中常常以錯誤零容忍自居,對團隊的錯誤”頤指氣使”,想來也是讓人極爲厭惡的。人非聖賢,高人亦如此,何況吾凡輩。有些錯誤換個角度反而是一種美,那我們就從遞臺階開始吧。"}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"link","attrs":{"href":"http://daye.me/2020/05/08/execuse-for-programmer-md/#01-%E7%AE%A1%E6%9D%80%E4%B8%8D%E7%AE%A1%E5%9F%8B","title":null}},{"type":"text","text":"01 管SHA不管埋"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"codeinline","content":[{"type":"text","text":"臺階:大名鼎鼎的J.U.C併發包"}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/c2/c280f0a2263d7ddb687385399b21b1e3.png","alt":null,"title":null,"style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"程序員皆知J.U.C包的造物主是併發大師Doug Lea。在jdk5之前對於線程同步使用的技術基本就是synchronized、wait、notify這些(用過jdk1.4或更早版本的老古董可以文末舉個手,大爺我從jdk1.3入坑)。這時的併發控制不夠優雅,性能也差的很,直到Doug Lea把JSR-166號提案提交到JCP組織("},{"type":"link","attrs":{"href":"https://jcp.xn--org%29%2Cjsr-166j-ey3xo85otuxb8x4gpbyc.u.xn--c-w74b91ls8scxonrj./","title":null},"content":[{"type":"text","text":"https://jcp.org),而這個JSR-166就是J.U.C的技術規範。"}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"更牛掰化的是,在提案之前Doug Lea早就寫完了基本類似現在J.U.C的整套原型代碼,並已經使用它長達3年之久了,我們真該慶幸老李沒有藏起來自斟自飲。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"blockquote","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"參考 The birth of J.U.C"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"link","attrs":{"href":"https://programmer.help/blogs/the-birth-of-j.u.c.html","title":null},"content":[{"type":"text","text":"https://programmer.help/blogs/the-birth-of-j.u.c.html"}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"即使如此牛掰,我們也要雞蛋裏挑骨頭。當使用 synchronized 關鍵字使對象阻塞時,通過線程dump能夠看到被該阻塞的對象信息,方便問題定位。而jdk5裏面的Lock等併發工具卻遺漏了這一點,致使dump線程時看不到阻塞對象的信息,因而不得不在jdk6中的LockSupport新增了含有阻塞對象的park方法。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"老李這種神人可能壓根不需要dump文件,就可以盲分析出線程問題所在。但是這可苦了我輩Javaer了呀,因爲代碼不僅是給人用的,還是方便給人修的,不然很多數碼家電都有厚厚一本操作手冊可不是當擺設的。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"blockquote","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"不過這個鍋到底是不是老李的,歷史過於悠久,搜遍Google亦無從考證,遂作罷。老李背不動總得有jdk的某個人背。"}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"管SHA不管埋"},{"type":"text","text":",個人覺得,是程序員羣體特別容易掉進去的一個錯誤陷阱。它像不像寫代碼不寫註釋的你,像不像通篇大段邏輯代碼卻沒有打印日誌或者打印無腦日誌(無助於排障)的你,像不像應用上線沒有接入日誌系統或者監控系統的你…現在,臺階已奉上,供君拾級而下。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"link","attrs":{"href":"http://daye.me/2020/05/08/execuse-for-programmer-md/#02-%E7%BB%A3%E8%8A%B1%E6%9E%95%E5%A4%B4","title":null}},{"type":"text","text":"02 繡花枕頭"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"codeinline","content":[{"type":"text","text":"臺階:Homebrew的作者谷歌面試被拒"}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/43/435c336697d8449bed2a8304887c63f2.png","alt":null,"title":null,"style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"平時用macOS做開發的同學一定對Homebrew這個軟件包管理工具不陌生,這個廣有知名度的軟件的作者Max Howell某一天去谷歌面試,面試官讓其在白板上徒手寫個反轉二叉樹的代碼實現,這位大神說不會,然後就沒有然後了,再然後就有了上面的twitter怒懟,再再然後LeetCode上架了這個算法題並標註爲Easy級別…"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"此熱門事件當時在程序員圈迅速發酵,引起正反兩派的激烈辯論。但雙方不管怎麼互懟,大部分人應該私下都偷偷的去把反轉代碼擼了幾遍,然後像模像樣的再把非遞歸的比如隊列算法再擼幾遍,頓時,感覺自己要超越世界級大牛了…至少在反轉二叉樹這塊…"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"說繡花枕頭略有些過,畢竟任誰都會有一些知識死角。反過來說,還是看我們怎麼定義這個問題,到底是不可避免的知識死角還是過於薄弱的基礎能力。"},{"type":"text","marks":[{"type":"strong"}],"text":"揚長避短是一種人生,那查漏補缺未嘗不是一種更積極的人生態度"},{"type":"text","text":"。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"link","attrs":{"href":"http://daye.me/2020/05/08/execuse-for-programmer-md/#03-%E7%8E%A9%E7%89%A9%E4%B8%A7%E5%BF%97","title":null}},{"type":"text","text":"03 玩物喪志"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"codeinline","content":[{"type":"text","text":"臺階:Unix本是用來玩遊戲的"}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/bd/bda215f0ff48714d25ec0e9f96e4c84c.png","alt":null,"title":null,"style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"現在我們開發環境所屬的操作系統無非Windows, Mac(Unix BSD分支)或Linux(類Unix),除了Windows其他兩個的內核鼻祖都是Unix。那麼當然地,作爲Unix的發明人 "},{"type":"text","marks":[{"type":"strong"}],"text":"Ken Thompson 和 Dennis Ritchie"},{"type":"text","text":",必然是鼻祖級的傳奇人物,更不用提他倆一個是B語言之父,一個是C語言之父了。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"何曾想,Unix的誕生只是因爲一個叫Space Travel的遊戲在當時的MULTICS系統上運行太慢,要遷移到一個更精簡的操作系統上。然後有了Unix,和它收割世界的故事了。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"blockquote","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Space Travel遊戲真身"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"link","attrs":{"href":"https://en.wikipedia.org/wiki/Space_Travel_(video_game)","title":null},"content":[{"type":"text","text":"https://en.wikipedia.org/wiki/Space_Travel_(video_game)"}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"link","attrs":{"href":"https://www.uvlist.net/game-164857-Space+Travel","title":null},"content":[{"type":"text","text":"https://www.uvlist.net/game-164857-Space+Travel"}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"有人因爲遊戲開發了外掛,有人因爲遊戲開發了Unix…看來玩遊戲並沒有那麼不堪,換個角度,遊戲確實也是用來放鬆和激發想象力的有效手段,只會機械的編程與鹹魚有何分別?那麼,工作中有些小夥伴玩心重,建議也不要急切的下定論。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"依然記得當年公司的編程規範考試,我找了個開源的PHP考試系統簡單修修改改後,部署發佈在了公司內網。考完後的閱卷原以爲平淡無奇,直到發現有人在編程題裏注入了XSS代碼,具體的彈窗內容已經不記得了,我只記得他當時錯了蠻多題,理應過不了考試,但是我依然給了他過,不只是因爲有趣還因爲作爲小鮮肉程序員有如此的知識厚度很難得。此時的我並不想拿規範考試束縛他。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"恩,足夠牛逼的人走到哪裏都會有特權,就是這麼回事。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"blockquote","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"附一個很有趣,Star高達38K的Github項目"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"link","attrs":{"href":"https://github.com/kelseyhightower/nocode","title":null},"content":[{"type":"text","text":"https://github.com/kelseyhightower/nocode"}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"link","attrs":{"href":"http://daye.me/2020/05/08/execuse-for-programmer-md/#04-%E7%A0%8D%E6%9D%90%E4%B8%8D%E8%AF%AF%E7%A3%A8%E5%88%80%E5%8A%9F","title":null}},{"type":"text","text":"04 砍材不誤磨刀功"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"codeinline","content":[{"type":"text","text":"臺階:寫算法我最優,但寫書我得慢"}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/f5/f5dbf7ee655564508ac224607a8e3f69.png","alt":null,"title":null,"style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"我們要再提一個神級大佬Donald Ervin Knuth, 中文名叫高德納。"}]},{"type":"blockquote","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"不少人以爲是Donald的音譯,叫人家高納德,以人家自己的首頁爲準"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"link","attrs":{"href":"https://www-cs-faculty.stanford.edu/~knuth/","title":null},"content":[{"type":"text","text":"https://www-cs-faculty.stanford.edu/~knuth/"}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"稱他爲算法之父毫不爲過,因爲我們現在用的數據結構、算法複雜度、算法分析符號啥的都是他發明的。當然更爲世人所熟知的是他的鉅著《The Art of Computer Programming》,簡稱 TAOCP,中文名 計算機程序設計藝術。原本出版社只想跟老高約一本關於編譯器和程序設計方面的書,結果老高四年沒寫完,手稿倒是寫了一堆,憋着勁要寫一本傳世之作,算來算去得整七卷。意料之外情理之中,剛剛寫完第三卷,就被計算機界奉爲神作,ACM的評委們也坐不住了,迫不及待要給老高頒發圖靈獎。所以至今,老高(當時36歲)仍舊是最年輕的圖靈獎獲得者。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"歷史繼續滾動,故事卻剛剛開始。拿到圖靈獎後不久老高就宣佈擱筆,理由是排版工具太差,不能忍了。緊接着,說江郎才盡、見好就收的非議如期而至,人老高神人怎會在乎爾等凡人的屁話,說擱筆就擱筆,一擱就是十年之久。期間老高可沒閒着,陸續創造了文字排版系統TEX(大名鼎鼎LaTeX的雛形)、字體設計系統METAFONT和文學化編程Literate Programming。再拿起筆寫完第四卷已是2008年,距離第三卷過去了30多年。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"你說30年,用再爛的排版系統怎麼也可以搗鼓出來一本書了吧?話是沒錯,但這和寫代碼不復用不抽象,就是CopyPaste有何區別呢?"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"blockquote","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"笑話一則"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"當年Linux之父Linus說:上帝在夢中告訴我,我做出了最優秀的操作系統。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"高德納回答說:我可沒這麼說過。"}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"程序員的工作目標從來不是最快而是最優,工作內容從來不是重複性勞動而是創造性工作"},{"type":"text","text":"。若因爲蹩腳的工具、繁冗的流程、糟糕的設計不能忍而影響了自己的交付進度,不用怕,程序員就該有程序員的樣子!"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"以上,共勉。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}}]}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章