Posted on January 14th, 2010 at 17:35 by fr3@K
The issue with boost::decay documentation that I blogged about 10 days ago has been fixed in trunk.
The issue with boost::decay documentation that I blogged about 10 days ago has been fixed in trunk.
前陣子看了 Hubert 的 一個 boost::exception 的例子, 猛然注意到自己不確定 boost::decay 的作用.
今天稍早, 跟一位同事聊到 Boost 的 lexical_cast. 打開了 Firefox 請出 Google, 想找到能幫助我介紹 lexical_cast 的資源. 意外地, Google 把我帶到讓我賺了介紹獎金, 現在跟我是同事的 Jeff, 談到 lexical_cast 的 文章.
在這篇文字的討論串, Jeff 寫道:
我覺得如果可以用這樣的寫法,那就太好了:
uint32_t ID = lexical_cast<auto>("1234567");甚至最好是:
template <class From, class To = auto> To lexical_cast(From s) {...} uint32_t ID = lexical_cast("1234567");Jeff Hung
In a recent post of Scott Wheeler’s – C and C++ are not the same language. He talked about differences between C and C++, and applications of different programming languages (C, C++, Java, Ruby) in his company.
In the post, Wheeler implemented observer pattern in C, C++ and Java, demonstrating some of his points – including how C and C++ are different from each other, and how C++ and Java are actually more alike.
Though I do agree with Wheeler’s conclusion for the most part, I failed to share his view in C, C++ and Java comparison. IMHO, his observer implementation in C++ is rather old school, or should I say it’s so Java.
上週看到了一篇引起我興趣的 blog – C++ Format String using boost::format. 冒著再次被人指為 屁的半死 的風險, 身為男子漢的我, 還是決定把心中的 替代解法 寫給了 Hubert 參考. Hubert 建議用 Boost.Format 的解法很好, 可我就是就是忍不住貪玩啊.
緣由交代完了. 有興趣看給 Hubert 參考的解法的朋友請自便, 因為接下來要談的不是它, 而是另一個沒那麼漂亮, 但卻挺有趣的解法.
(more…)
Not long ago, I blogged about how it was difficult to adopt Free libraries in my previous projects at work.
Just today, when I was exploring the compay repository, I see boost sits comfortably under a folder named “3rd_party” in one of my previous projects, along with a couple of tiny Free libraries I wrote.
Apparently, I was wrong and didn’t try hard enough. Going to find the man who made it happen and pay him my respect tomorrow.
Keiko 寫了篇 討論 DSL 的文字. 這篇文字不短, 有層次. 有他說的 “學院派式” 的格調. 讓我有一種在看一份探討輪胎直徑與胎壓以及胎壁厚度之間關係的 paper 的 feel. 相形之下, 這裡寫的東西看起來更像是黑手示範如何補胎換胎的 howto.
好了, 細節不多談, 建議看官移架拜讀. 重點是, 本要在 comment 裏寫 code, 但這該死的 blogger 超難用, 讓我想起當年 從 blogger 離家出走 的原因. 又扯遠了, 回到我想回應給 Keiko 的東西.
(more…)
在 C++ 的世界裡, 正確的 exception handling 是專業的 C++ programmer 不可或缺的技巧. 雖然它的概念並不困難, 但實作起來卻常不見得那麼容易.
要做到正確的 exception handling, 首先必須要了解什麼是 exception safety. 一個需要與 exception 打交道的 component 可在其介面實作人稱 Abrahams guarantees 的三種 exception safety 保證之一:
允許操作失敗時改變物件的狀態, 但不能有 resource leak. 且該物件的狀態必須是可靠的仍然可以被解構, 操作失敗後該物件的狀態可以是不完全能被預測的.
操作後的狀態只能是成功完成, 或是將該物件回復到操作之前的狀態並拋出一個 exception.
操作不會拋出 exception.
Microsoft 的 MFC 是最早被大量採用 (massive adoption) 的 C++ library 之一. 等到我開始接觸 C++ Standard Library 這東西都已經是玩了兩年 MFC 以後的事. 還記得, 從一開始對 MFC 的讚嘆與擁抱, 幾年後對它的不屑, 到更後來的理解 (理解不好其實也是有原因的).
即便不少 programmer 知道 MFC 是一套瑕疵遍佈的 library, 可能也知道那些地方有問題. 但它以及部份其他 library 聯手對於更多 C++ programmer 造成的傷害已經留下不容易抹滅的痕跡. 它讓許多 programmer 以為這些東西本來就該這樣 (that’s the way things supposed to be), 當有一天這些被誤導的 programmer 有機會可以選擇另一套 library 或是自行設計的時候, 很容易就陷入 MFC 帶給他們已先入為主的錯誤觀念.
Except where otherwise noted, COdE fr3@K by
fr3@K is licensed under a
Creative Commons Attribution-Share Alike 3.0 License.