[翻譯] 啥時找 library?啥時自幹?

作者: PsMonkey (痞子軍團團長)   2015-02-27 14:18:26
blog 版:http://blog.dontcareabout.us/2015/02/library.html
BBS 版以 markdown 語法撰寫
原文網址:http://games.greggman.com/game/
when-to-find-a-library-vs-when-to-write-code/
譯註:我幾乎完全不認同這篇的說法,
更不用說 [HappyFunTimes] 也是一個 library [大笑]。
只是拿來恢復一下翻譯的感覺...
身為一個 C / C++ 碼農,除非是很大的 project,不然我很少找 library。
舉例來說,如果我需要讀 BMP / TGA 檔,帳面上要寫的程式碼不到 100 行。
看一下資料格式、寫一些程式、打完收工。
要是我需要載入 JPG / PNG 這些格式異常複雜的檔案,
我終究會去找一個 library。
我現在寫 JavaScript 就不太一樣,
在 JavaScript 的世界中有數以萬計[針對各種狀況的小型 library][1],
讓我不知道該自幹程式還是找找看有沒有 library。
這常常讓我覺得很浪費時間。
例如我要有一個非常簡單的功能:把字串裡頭的關鍵字換掉:
replaceParams("Hello %(name)s", {name: "World"});
// produces:
// Hello World
後來為了可以這樣搞,所以拓展到 20 行:
replaceParams(
"Hello %(name)s from %(user.country)s",
{
name: "Joe",
user: {
country:"USA",
},
});
// produces:
// Hello Joe from USA
最近我希望可以用路徑插入其他檔案,像這樣:
replaceParams("->%(insertfile: foo/bar/moo.txt)s<-");
如果 `moo.txt` 裡頭是 `this-and-that`,結果會是:
作者: AmosYang (泛用人型編碼器)   2015-03-01 00:55:00
markdown is dead. long live commonmark :D

Links booklink

Contact Us: admin [ a t ] ucptt.com